Compare commits

...

3 Commits

Author SHA1 Message Date
Dianne Skoll a933c8bc69 Document that we don't read subdirectories when expanding *.rem.
Remind unit tests / tests (push) Successful in 31s
2024-12-06 20:21:09 -05:00
Dianne Skoll 087fbfd8e6 If a path returned by glob is a directory, ignore it. 2024-12-06 20:18:45 -05:00
Dianne Skoll ff641d7990 Refuse to open directories. 2024-12-06 20:09:30 -05:00
2 changed files with 29 additions and 11 deletions
+11 -9
View File
@@ -14,11 +14,12 @@ If \fIfilename\fR is specified as a single dash '-', then \fBRemind\fR
takes its input from standard input.
.PP
If \fIfilename\fR happens to
be a directory rather than a plain file, then \fBRemind\fR reads all of
the files in that directory that match the pattern "*.rem". The files
are read in sorted order; the sort order may depend on your locale, but
should match the sort order used by the shell to expand "*.rem".
If \fIfilename\fR happens to be a directory rather than a plain file,
then \fBRemind\fR reads all of the files (but not any subdirectories!)
in that directory that match the pattern "*.rem". The files are read
in sorted order; the sort order may depend on your locale, but should
match the sort order used by the shell to expand "*.rem".
.PP
\fBRemind\fR reads its files starting from the beginning to the end, or
until it encounters a line whose sole content is "__EOF__" (without the quotes.)
@@ -1925,10 +1926,11 @@ administrator.)
If you specify a filename of "-" in the \fBINCLUDE\fR command, \fBRemind\fR
will begin reading from standard input.
.PP
If you specify a \fIdirectory\fR as the argument to \fBINCLUDE\fR, then
\fBRemind\fR will process all files in that directory that match the shell
pattern "*.rem". The files are processed in sorted order; the sort order
matches that used by the shell when it expands "*.rem".
If you specify a \fIdirectory\fR as the argument to \fBINCLUDE\fR,
then \fBRemind\fR will process all files (but not subdirectories!) in
that directory that match the shell pattern "*.rem". The files are
processed in sorted order; the sort order matches that used by the
shell when it expands "*.rem".
.PP
Note that the file specified by an \fBINCLUDE\fR command is interpreted
relative to the \fIcurrent working directory of the Remind process\fR.
+18 -2
View File
@@ -726,6 +726,8 @@ static int SetupGlobChain(char const *dirname, IncludeStruct *i)
size_t l;
int r;
glob_t glob_buf;
struct stat sb;
DirectoryFilenameChain *dc = CachedDirectoryChains;
i->chain = NULL;
@@ -808,6 +810,16 @@ static int SetupGlobChain(char const *dirname, IncludeStruct *i)
/* Add the files to the chain backwards to preserve sort order */
for (r=glob_buf.gl_pathc-1; r>=0; r--) {
if (stat(glob_buf.gl_pathv[r], &sb) < 0) {
/* Couldn't stat the file... fuggedaboutit */
continue;
}
/* Don't add directories */
if (S_ISDIR(sb.st_mode)) {
continue;
}
FilenameChain *ch = malloc(sizeof(FilenameChain));
if (!ch) {
globfree(&glob_buf);
@@ -816,8 +828,6 @@ static int SetupGlobChain(char const *dirname, IncludeStruct *i)
return E_NO_MEM;
}
/* TODO: stat the file and only add if it's a plain file and
readable by us */
ch->filename = StrDup(glob_buf.gl_pathv[r]);
if (!ch->filename) {
globfree(&glob_buf);
@@ -1149,6 +1159,12 @@ static int CheckSafety(void)
return 0;
}
if (S_ISDIR(statbuf.st_mode)) {
fclose(fp);
fp = NULL;
return 0;
}
if (!CheckSafetyAux(&statbuf)) {
fclose(fp);
fp = NULL;