From ed5c4e770a27862813c0182be8680abeb005d15b Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 30 Jan 2008 13:43:15 +0100 Subject: Improve "rmdir --ignore-fail-on-non-empty" * src/rmdir.c (remove_parents, main): With --ignore-fail-on-non-empty, suppress a diagnostic also for other errno values, which can arise with read-only media or when the parent directory has the immutable attribute (set via chattr +i). (errno_may_be_empty, ignorable_failure): New functions. * src/remove.c (is_empty_dir): Move function to ... * src/system.h (is_empty_dir): ...here, and make it inline. Suggested by Josselin Mouette in via Bob Proulx. * NEWS: Mention the improvement. --- src/remove.c | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) (limited to 'src/remove.c') diff --git a/src/remove.c b/src/remove.c index de8f5ffc9..fe603bbc0 100644 --- a/src/remove.c +++ b/src/remove.c @@ -1,5 +1,5 @@ /* remove.c -- core functions for removing files and directories - Copyright (C) 88, 90, 91, 1994-2007 Free Software Foundation, Inc. + Copyright (C) 88, 90, 91, 1994-2008 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -726,36 +726,6 @@ AD_is_removable (Dirstack_state const *ds, char const *file) return ! (top->unremovable && hash_lookup (top->unremovable, file)); } -/* Return true if DIR is determined to be an empty directory. */ -static bool -is_empty_dir (int fd_cwd, char const *dir) -{ - DIR *dirp; - struct dirent const *dp; - int saved_errno; - int fd = openat (fd_cwd, dir, - (O_RDONLY | O_DIRECTORY - | O_NOCTTY | O_NOFOLLOW | O_NONBLOCK)); - - if (fd < 0) - return false; - - dirp = fdopendir (fd); - if (dirp == NULL) - { - close (fd); - return false; - } - - errno = 0; - dp = readdir_ignoring_dot_and_dotdot (dirp); - saved_errno = errno; - closedir (dirp); - if (dp != NULL) - return false; - return saved_errno == 0 ? true : false; -} - /* Return -1 if FILE is an unwritable non-symlink, 0 if it is writable or some other type of file, a positive error number if there is some problem in determining the answer. -- cgit v1.2.3-54-g00ecf