Message ID | 8ac5e94a3930cdd2aee9ea86acda3155674b635c.1711035529.git.ps@pks.im (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | reftable: fix tests being broken by NFS' delete-after-close semantics | expand |
Patrick Steinhardt <ps@pks.im> writes: > while ((d = readdir(dir))) { > - if (!strcmp(d->d_name, "..") || !strcmp(d->d_name, ".")) > + /* > + * Besides skipping over "." and "..", we also need to > + * skip over other files that have a leading ".". This > + * is due to behaviour of NFS, which will rename files > + * to ".nfs*" to emulate delete-on-last-close. > + * > + * In any case this should be fine as the reftable > + * library will never write files with leading dots > + * anyway. > + */ > + if (starts_with(d->d_name, ".")) > continue; Sounds good. We should count what we positively consider what we wrote, not random cruft somebody else might have dropped in the directory, and this is a good first thing to do. Will queue. Thanks.
Patrick Steinhardt <ps@pks.im> writes: > Fix this bug by skipping over any files that start with a leading dot > when counting files. While we could explicitly check for a prefix of > ".nfs", other network file systems like SMB for example do the same > trickery but with a ".smb" prefix. In any case though, this loosening of > the assertion should be fine given that the reftable library would never > write files with leading dots by itself. I'm fully supportive of this, as this will also fix any issues possibly caused by .DS_Store files created by Finder on macOS, although it's very unlikely they will be created in these tests. -- Toon
diff --git a/reftable/stack_test.c b/reftable/stack_test.c index 509f486623..621578fda8 100644 --- a/reftable/stack_test.c +++ b/reftable/stack_test.c @@ -38,7 +38,17 @@ static int count_dir_entries(const char *dirname) return 0; while ((d = readdir(dir))) { - if (!strcmp(d->d_name, "..") || !strcmp(d->d_name, ".")) + /* + * Besides skipping over "." and "..", we also need to + * skip over other files that have a leading ".". This + * is due to behaviour of NFS, which will rename files + * to ".nfs*" to emulate delete-on-last-close. + * + * In any case this should be fine as the reftable + * library will never write files with leading dots + * anyway. + */ + if (starts_with(d->d_name, ".")) continue; len++; }