summaryrefslogtreecommitdiff
path: root/src/remove.c
AgeCommit message (Collapse)Author
2007-07-10Change "version 2" to "version 3" in all copyright notices.Jim Meyering
2007-03-25Avoid the need for euidaccess and/or lstat on every directory entryPaul Eggert
with 'rm -r dir' (without -f), if we are root, or if we are removing a directory tree that is full of symbolic links. * bootstrap.conf (gnulib_modules): Add write-any-file. * src/copy.c: Include write-any-file.h. (UNWRITABLE): Remove macro, replacing with.... (writable_destination): New function, which uses can_write_any_file to avoid the need for euidaccess when we are privileged. (overwrite_prompt, abandon_move): Use it. * src/remove.c: Include write-any-file.h. (D_TYPE): New macro. (DT_UNKNOWN, DT_DIR, DT_LNK) [!HAVE_STRUCT_DIRENT_D_TYPE]: New macros. (write_protected_non_symlink): Don't bother to stat if we can write any file. (prompt): New arg PDIRENT_TYPE. All callers changed. Use readdir dirent type to avoid the need for 'lstat' on each directory entry in cases like 'rm -r dir', if we are root, or if the tree is full of symbolic links. (DT_IS_KNOWN, DT_MUST_BE): Remove. (remove_entry): New arg DIRENT_TYPE_ARG. All callers changed.
2007-03-08rm without -f: give a better diagnostic when euidaccess fails.Jim Meyering
* src/remove.c (write_protected_non_symlink): Return int, not bool, so that we can indicate failure too (as a postive error number). (prompt): If write_protected_non_symlink fails, report that error number and fail rather than charging ahead and removing the dubious entry. Redo the logic of printing a diagnostic so that we need to invoke quote (full_filename (...)) only once. More details at: <http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/9952/focus=9996>
2007-01-17Make "rm --interactive=never ..." never prompt.Jim Meyering
* NEWS: Mention this. * src/remove.h (enum rm_interactive): New ternary type. (struct rm_options) [interactive]: Use it, here -- rather than bool. * src/remove.c (prompt): Reflect type change. * src/mv.c (rm_option_init): Initialize to RMI_NEVER now. * src/rm.c (main): Add a FIXME comment for '-d' option. Adapt to type change of rm_options.interactive. * tests/rm/i-never: New file. Test for the above fix. * tests/rm/Makefile.am (TESTS): Add i-never.
2007-01-15* src/remove.c (remove_dir): Don't use errno in diagnostic.Jim Meyering
Root-only test failure reported by Alex van Hout and Jon Grosshart in <http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/9415/focus=9415>.
2006-12-30Clean up after the change of 2006-12-28.Jim Meyering
* src/remove.c (AD_pop_and_chdir): Change **DIRP parameter to *DIRP, now that this function never modifies the pointer. Adjust comments and code accordingly. (remove_dir): Set "dirp" to NULL right after AD_pop_and_chdir call, now that AD_pop_and_chdir no longer does that.
2006-12-28When moving "up" the hierarchy, be careful to remove a just-emptiedJim Meyering
directory before opening ".", to avoid trouble with file system implementations that cache readdir results at opendir-time. * src/remove.c (AD_pop_and_chdir): Add a file descriptor parameter. Don't update **DIRP. Don't call fdopendir here. (remove_dir): Call fdopendir here instead. Report and patch from Mikulas Patocka: <http://lists.gnu.org/archive/html/bug-coreutils/2006-12/msg00170.html>
2006-12-21"rm -rf /etc/motd" (run by non-root) now prints a diagnostic.Jim Meyering
* src/remove.c (remove_entry): Handle EACCES for a non-directory, too. Karl Berry reported that a cross-partition "mv /etc/issue ~" failed with the um,... suboptimal diagnostic, "mv: cannot remove `/etc/issue': Not a directory". * tests/rm/Makefile.am (TESTS): Add fail-eacces. * tests/rm/fail-eacces: New file. * NEWS: Mention that both mv and rm are affected.
2006-11-26* src/remove.c (fd_to_subdirp): Remove unused parameter, ds.Jim Meyering
Update callers.
2006-11-26Port parts of the code to C89 to minimize the need for c99-to-c89.diff,Paul Eggert
while trying to retain the readability of C99 as much as possible. * src/remove.c (close_preserve_errno): Remove. (fd_to_subdirp): Rewrite to avoid the need for decl after statement. Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
2006-11-26* src/remove.c (rm): Move cycle_check_init call into callee...Paul Eggert
Use an else clause in place of a "continue" statement. Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
2006-11-26* src/remove.c (AD_ensure_initialized): New function.Paul Eggert
after statement. Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
2006-11-26* src/remove.c (AD_pop_and_chdir): Return prev_dir rather than storing throughPaul Eggert
a pointer argument. All uses changed. Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
2006-11-26* src/remove.c (cache_stat_init): Return its argument, for convenience.Paul Eggert
Update the caller in remove_dir. Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
2006-11-26* src/remove.c (rm_1): Remove decl of local, fd_cwd.Paul Eggert
Replace each of two uses with literal AT_FDCWD. Signed-off-by: Paul Eggert <eggert@cs.ucla.edu>
2006-10-25new feature: rm accepts new option: --one-file-systemJim Meyering
Suggested by Steve McIntyre in <http://bugs.debian.org/392925>. * src/remove.h (struct rm_options) [one_file_system]: New member. * src/rm.c (rm_option_init): Initialize it. (usage): Document the option. * src/mv.c (rm_option_init): Likewise. * src/remove.c (remove_dir): With --one-file-system and --recursive, for each directory command line argument, do not affect a file system different from that of the starting directory. And give a diagnostic. * src/rm.c (ONE_FILE_SYSTEM): New enum. (main): Handle new option. * tests/rm/one-file-system: Test the above. * tests/rm/Makefile.am (TESTS): Add one-file-system. * tests/Makefile.am (check-root): Add the rm/one-file-system test to the list. (EXTRA_DIST): Add other-fs-tmpdir. * tests/mv/setup: Removed. Renamed to... * tests/other-fs-tmpdir: ...this new file. * tests/mv/Makefile.am (EXTRA_DIST): Remove setup. * tests/mv/acl: Reflect renaming: use ../other-fs-tmpdir. * tests/mv/backup-is-src: Likewise. * tests/mv/hard-link-1: Likewise. * tests/mv/leak-fd: Likewise. * tests/mv/mv-special-1: Likewise. * tests/mv/part-fail: Likewise. * tests/mv/part-hardlink: Likewise. * tests/mv/part-rename: Likewise. * tests/mv/part-symlink: Likewise. * tests/mv/partition-perm: Likewise. * tests/mv/to-symlink: Likewise. * tests/mv/into-self-2: Likewise. [doc/ChangeLog] * coreutils.texi (rm invocation): Describe --one-file-system.
2006-10-05* src/dd.c (flags): noatime and nofollow now depend onPaul Eggert
HAVE_WORKING_O_NOATIME and HAVE_WORKING_O_NOFOLLOW, too. (usage): Output info about noatime and nofollow only if they are known to work. * src/remove.c (AD_push): Inspect HAVE_WORKING_O_NOFOLLOW rather than O_NOFOLLOW, when testing whether it's possible to avoid a race condition reliably.
2006-10-03* src/remove.c (nonexistent_file_errno): Remove ENAMETOOLONG.Jim Meyering
Paul Eggert pointed out that the specified file may exist, in spite of such an errno value. * tests/rm/Makefile.am (TESTS): Remove ignore-name-too-long. * tests/rm/ignore-name-too-long: Remove file.
2006-10-03* src/remove.c (remove_entry): With -f, exit successfully in spiteJim Meyering
of a missing file under some very unusual conditions (with errno being any of ENOENT, ENOTDIR, ENAMETOOLONG).
2006-10-03With --force (-f), rm no longer fails for ENOTDIR.Jim Meyering
* src/remove.c (ignorable_missing): New function. Use it everywhere, rather than open-coding the test. Andreas Schwab reported the ENOTDIR problem. (ignorable_missing): Similarly, don't fail for ENAMETOOLONG. * NEWS: Mention the bug fix. * tests/rm/ignorable: New file. Test for the ENOTDIR case. * tests/rm/ignore-name-too-long: New file. Test for ENAMETOOLONG. * tests/rm/Makefile.am (TESTS): Add the new file names.
2006-09-29[ChangeLog]Jim Meyering
Since any system may be affected by the Darwin readdir bug, perform the extra rewinddir unconditionally. The performance impact of rewinding a directory is negligible. * src/remove.c (NEED_REWIND): Define to use CONSECUTIVE_READDIR_UNLINK_THRESHOLD unconditionally. [m4/ChangeLog] * readdir.m4: Remove file once again. * jm-macros.m4: Remove reference to gl_FUNC_READDIR.
2006-09-29Work around a readdir bug in Darwin 7.9.0 (MacOS X 10.3.9) on HFS+Jim Meyering
and NFS, whereby rm would not remove all files in a directory. * src/remove.c (CONSECUTIVE_READDIR_UNLINK_THRESHOLD): Reduce to 10. (NEED_REWIND): New macro, so that we incur the cost of the work-around rewinddir only on afflicted systems. * NEWS: Clarify and correct. * tests/rm/readdir-bug: New file. Test for the above fix. * tests/rm/Makefile.am (TESTS): Add it. Prompted by testing and analysis from Bruno Haible: http://lists.gnu.org/archive/html/bug-coreutils/2006-09/msg00326.html
2006-09-26* NEWS: rm works around a bug in Darwin 8.6.1 w/NFS that keptJim Meyering
it from removing a directory containing 188 or more entries. * src/remove.c (CONSECUTIVE_READDIR_UNLINK_THRESHOLD): Decrease by 20, go work around the buggy readdir on Darwin 8.6.1 with NFS. Reported by Matthew Woehlke.
2006-09-11* src/remove.c (remove_dir): Move new cache_stat_init call ontoJim Meyering
it's own line. (rm_1): Move declaration of "st" and new cache_stat_init call "down" to nearer where they're used.
2006-09-03Don't include dirname.h, since system.h does it now.Paul Eggert
(cache_fstatat, cache_stat_init): New functions. (cache_statted, cache_stat_ok): New functions. (write_protected_non_symlink): Remove struct stat ** buf_p arg, which is no longer needed with the new functions. All callers changed. (prompt, is_dir_lstat, remove_entry, remove_dir): New struct stat * arg. All callers changed. (write_protected_non_symlink, prompt, is_dir_lstat, remove_entry): (remove_cwd_entries, remove_dir, rm_1): Use and maintain the file status cache. (prompt, remove_entry): Omit the first "directory" in the diagnostic "Cannot remove directory `foo': is a directory". This causes "rm" to pass a test case that it would otherwise fail now that it "knows" more about its argument. I think the diagnostic is better without the first "directory" anyway. (prompt): Remove the no-longer-needed IS_DIR arg; all callers changed. (rm_1): Reject attempts to remove /, ./, or ../.
2006-08-27* src/system.h (DOT_OR_DOTDOT): Remove macro. Rewrite as a...Jim Meyering
(dot_or_dotdot): ...new static inline function. * src/remove.c (rm_1): Reflect this renaming. * src/ls.c (basename_is_dot_or_dotdot): Likewise.
2006-07-03Plug another unusual leak.Jim Meyering
(AD_mark_helper): Free malloc'd filename if hash_insert says that string is already in the hash table.
2006-07-03The dev/inode of the topmost directory in each hierarchy were notJim Meyering
being recorded. * src/remove.c (remove_cwd_entries): Don't call cycle_check here. (AD_push): Call it from here instead.
2006-07-03Fix two small leaks.Jim Meyering
* src/remove.c (AD_stack_clear): New function. (rm_1): Use it. (AD_pop_and_chdir): Free *prev_dir just before longjmp.
2006-06-28* src/system.h (CLOSEDIR): Remove. All uses changed to closedir.Paul Eggert
2006-06-26Attempt rmdir (actually, unlinkat-with-AT_REMOVEDIR) upon anyJim Meyering
fd_to_subdirp failure, not just when errno == EACCES. * src/remove.c (remove_dir): Use unlinkat-with-AT_REMOVEDIR, not rmdir, here, even though rmdir may happen to be adequate.
2006-06-26* NEWS: rm no longer fails to remove an empty, unreadable directoryJim Meyering
* src/remove.c (remove_cwd_entries): If we can't open a directory, and the failure is not being ignored, try to remove the directory with rmdir (aka unlinkat-with-AT_REMOVEDIR), in case it's empty. Problem report and test case from Paul Eggert in <http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/7425>. * tests/rm/empty-inacc: New test, for the above.
2006-06-25tweak grammar in commentJim Meyering
2006-03-26(rm_1): Use new last_component, in place of base_name.Jim Meyering
2006-03-12(AD_pop_and_chdir): Use new macro,Jim Meyering
CYCLE_CHECK_REFLECT_CHDIR_UP, rather than open-coding it.
2006-03-10Fix a bug whereby a user with write access to a directory being removedJim Meyering
could cause the removal of that directory to fail with an erroneous diagnostic about a directory cycle. Reported by Vineet Chadha. (AD_pop_and_chdir): If the directory we're about to leave (and try to rmdir) is the one whose dev_ino is being used to detect a cycle, reset cycle_check_state.dev_ino to that of the parent.
2006-02-12fix typo in commentJim Meyering
2006-02-11rm -r must remove an empty directory, even if it is inaccessible.Jim Meyering
(close_preserve_errno): New function. (fd_to_subdirp): Don't print a diagnostic in this function. Do it from the callers instead, unless rmdir succeeds. (remove_cwd_entries, remove_dir): Adjust callers.
2006-01-06(rm_1): Remove `static' attribute on local `status'.Jim Meyering
First off, the attribute should have been `volatile' (not static) to avoid longjmp-related risk of clobber. Secondly, now there is no longer any risk of a local variable being clobbered, so there's no need for any attribute at all.
2006-01-05Give a few functions the inline attribute.Jim Meyering
(AD_pop_and_chdir): Use gotos to avoid some duplication. (AD_push): Rewrite an assertion so that the entire computation goes away when assertions are turned off.
2005-12-27(fd_to_subdirp): Open with O_DIRECTORY | O_NOCTTYPaul Eggert
| O_NOFOLLOW too, for consistency with other dir-openers. Use POSIX-preferred O_NONBLOCK rather than O_NDELAY. (is_empty_dir): Likewise.
2005-12-17(is_empty_dir): Open with O_NDELAY, so we don't hang, e.g., on a named pipe.Jim Meyering
(OPEN_NO_FOLLOW_SYMLINK): Remove definition. Use O_NOFOLLOW in place of all uses, since it is guaranteed (system.h) to be defined.
2005-12-17(OPENAT_CWD_RESTORE__REQUIRE): Remove.Paul Eggert
(OPENAT_CWD_RESTORE__ALLOW_FAILURE): Likewise. (fd_to_subdirp): Remove openat_cwd_restore_allow_failure arg; its value is now signified by whether cwd_errno is null. (fd_to_subdirp, remove_dir, rm_1); Change cwd failure indicator from pointer-to-bool to pointer-to-errno-value. All callers changed. (rm_1): Don't bother setting a local cwd failure flag and then ORing it into the caller's. Just set the caller's. (rm): Use cwd failure errno value to print a slightly-better diagnostic.
2005-11-23(rm): Don't assume C99 for-loop syntax.Paul Eggert
2005-11-22whoops. Add back decl/definition of n_lengths.Jim Meyering
2005-11-22(AD_push): Remove debugging cruft.Jim Meyering
2005-11-22tweak commentsJim Meyering
2005-11-22Rewrite. Now, this module is reentrant on systemsJim Meyering
that provide openat (Solaris), and on systems like Linux+procfs where our openat emulation code is reentrant. This also fixes a few low-probability leaks and eliminates some code that could, in very unusual circumstances, cause rm() (via a callee) to exit.
2005-11-17(AD_mark_helper): Make a `char *' parameter `const'.Jim Meyering
(AD_mark_current_as_unremovable): Likewise, but for a local. (rm_1): Likewise.
2005-11-02(remove_entry): Emit a better diagnostic when rmJim Meyering
(without -r) fails to remove a directory on a non-Linux system. This change affects only newer Solaris systems (with priv_* functions like priv_allocset). Reported by Keith Thompson.