[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] */*/ glob pattern bug
From: |
spagoveanu |
Subject: |
[PATCH] */*/ glob pattern bug |
Date: |
Wed, 20 Jun 2018 02:03:48 +0300 |
When using gnu make on a system with glibc (eg. Debian Stretch),
a glob pattern ending in a slash is also matching regular files,
but only in subdirectories:
$ mkdir -p dir/subdir
$ cd dir
$ touch file1 subdir/file2
$ echo 'test:; @echo $(wildcard */ */*/)' | make -f -
subdir/ subdir/file2
$ echo 'test: */ */*/; @echo "$?" != */ */*/' | make -f -
subdir/ subdir/file2 != subdir/ */*/
It happens because in the gl->gl_readdir callback supplied to glob(),
dirent->d_type is set to DT_UNKNOWN, and the glob() implementation
in glibc assumes that such a directory entry *cannot* possibly be a
regular file.
In the patch below I'm simply passing the actual d_type down to glob();
this is the right thing to do even if they fix it in glibc, because
it saves an extra stat() syscall for each dirent.
diff --git a/src/dir.c b/src/dir.c
index c343e4c..f546766 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -407,6 +407,7 @@ struct dirfile
const char *name; /* Name of the file. */
size_t length;
short impossible; /* This file is impossible. */
+ unsigned char type;
};
static unsigned long
@@ -731,6 +732,9 @@ dir_contents_file_exists_p (struct directory_contents *dir,
#else
df->name = strcache_add_len (d->d_name, len);
#endif
+#ifdef _DIRENT_HAVE_D_TYPE
+ df->type = d->d_type;
+#endif
df->length = len;
df->impossible = 0;
hash_insert_at (&dir->dirfiles, df, dirfile_slot);
@@ -1242,7 +1246,7 @@ read_dirstream (__ptr_t stream)
d->d_namlen = len - 1;
#endif
#ifdef _DIRENT_HAVE_D_TYPE
- d->d_type = DT_UNKNOWN;
+ d->d_type = df->type;
#endif
memcpy (d->d_name, df->name, len);
return d;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] */*/ glob pattern bug,
spagoveanu <=