mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 23:08:40 +02:00
If a path returned by glob is a directory, ignore it.
This commit is contained in:
14
src/files.c
14
src/files.c
@@ -726,6 +726,8 @@ static int SetupGlobChain(char const *dirname, IncludeStruct *i)
|
|||||||
size_t l;
|
size_t l;
|
||||||
int r;
|
int r;
|
||||||
glob_t glob_buf;
|
glob_t glob_buf;
|
||||||
|
struct stat sb;
|
||||||
|
|
||||||
DirectoryFilenameChain *dc = CachedDirectoryChains;
|
DirectoryFilenameChain *dc = CachedDirectoryChains;
|
||||||
|
|
||||||
i->chain = NULL;
|
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 */
|
/* Add the files to the chain backwards to preserve sort order */
|
||||||
for (r=glob_buf.gl_pathc-1; r>=0; r--) {
|
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));
|
FilenameChain *ch = malloc(sizeof(FilenameChain));
|
||||||
if (!ch) {
|
if (!ch) {
|
||||||
globfree(&glob_buf);
|
globfree(&glob_buf);
|
||||||
@@ -816,8 +828,6 @@ static int SetupGlobChain(char const *dirname, IncludeStruct *i)
|
|||||||
return E_NO_MEM;
|
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]);
|
ch->filename = StrDup(glob_buf.gl_pathv[r]);
|
||||||
if (!ch->filename) {
|
if (!ch->filename) {
|
||||||
globfree(&glob_buf);
|
globfree(&glob_buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user