diff options
| author | Lennart Poettering <lennart@poettering.net> | 2022-05-04 10:53:00 +0200 |
|---|---|---|
| committer | Lennart Poettering <lennart@poettering.net> | 2022-05-04 13:29:14 +0200 |
| commit | db55bbf29b8d0268884348bf3270b8b2a2db3b31 (patch) | |
| tree | f17d57f6f02880a87ac4fb067768b797a0fe1d7b /src/basic/stat-util.h | |
| parent | 080b8c2ace2dcc4ee3faf5b0ee95f5117aa27dab (diff) | |
| download | systemd-db55bbf29b8d0268884348bf3270b8b2a2db3b31.tar.gz | |
stat-util: fix dir_is_empty() with hidden/backup files
This is a follow-up for f470cb6d13558fc06131dc677d54a089a0b07359 which in
turn is a follow-up for a068aceafbffcba85398cce636c25d659265087a.
The latter started to honour hidden files when deciding whether a
directory is empty. The former reverted to the old behaviour to fix
issue #23220.
It introduced a bug though: when a directory contains a larger number of
hidden entries the getdents64() buffer will not suffice to read them,
since we just allocate three entries for it (which is definitely enough
if we just ignore the . + .. entries, but not ig we ignore more).
I think it's a bit confusing that dir_is_empty() can return true even if
rmdir() on the dir would return ENOTEMPTY. Hence, let's rework the
function to make it optional whether hidden files are ignored or not.
After all, I looking at the users of this function I am pretty sure in
more cases we want to honour hidden files.
Diffstat (limited to 'src/basic/stat-util.h')
| -rw-r--r-- | src/basic/stat-util.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/basic/stat-util.h b/src/basic/stat-util.h index 4483ceb7de..ce3c8cccfe 100644 --- a/src/basic/stat-util.h +++ b/src/basic/stat-util.h @@ -17,14 +17,14 @@ int is_dir(const char *path, bool follow); int is_dir_fd(int fd); int is_device_node(const char *path); -int dir_is_empty_at(int dir_fd, const char *path); -static inline int dir_is_empty(const char *path) { - return dir_is_empty_at(AT_FDCWD, path); +int dir_is_empty_at(int dir_fd, const char *path, bool ignore_hidden_or_backup); +static inline int dir_is_empty(const char *path, bool ignore_hidden_or_backup) { + return dir_is_empty_at(AT_FDCWD, path, ignore_hidden_or_backup); } -static inline int dir_is_populated(const char *path) { +static inline int dir_is_populated(const char *path, bool ignore_hidden_or_backup) { int r; - r = dir_is_empty(path); + r = dir_is_empty(path, ignore_hidden_or_backup); if (r < 0) return r; return !r; |
