summaryrefslogtreecommitdiff
path: root/src/remove.c
AgeCommit message (Collapse)Author
2008-06-03use gnulib's progname moduleJim Meyering
* bootstrap.conf (gnulib_modules): Add progname. * src/*.c (program_name): Remove declaration. * (main): Call set_program_name rather than setting program_name. * src/nice.c (main): Cast program_name to "(char *)". * src/prog-fprintf.c: Include "system.h" * src/system.h: Include "progname.h". * maint.mk (sc_program_name): Adjust rule. Suggestion from Eric Blake.
2008-04-06remove.c: accommodate systems with negative errno valuesJim Meyering
This is required at least on Haiku and BeOS. * src/remove.c (write_protected_non_symlink): Return 1 for a write- protected non-symlink, 0 if we determine it's not, and -1 upon error (setting errno accordingly only in this final case). (prompt): Deal with the changed semantics of the above function. Based on this patch from Axel Dörfler: http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/13071
2008-03-31"rm -r DIR" would mistakenly prompt about very long namesJim Meyering
* src/remove.c (write_protected_non_symlink): Return 0(-1) when euidaccess_stat pronounces a writable(not-writable) file, not -1(0). * tests/rm/deep-2: New file. Test for the above-fixed bug. * tests/rm/Makefile.am (TESTS): Add deep-2. Discovered while reviewing this change: http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/13071
2008-03-21remove.c: Accommodate systems with negative errno values.Ingo Weinhold
* src/remove.c (cache_fstatat): Store errno value directly in the st_ino field, rather than trying to shoehorn it into st_size. This is required at least on BeOS and Haiku.
2008-01-30Now that system.h defines is_empty_dir, include "openat.h".Jim Meyering
* src/system.h: Include "openat.h" here, ... * src/chcon.c: ... not here. * src/chmod.c: Likewise. * src/chown-core.c: Likewise. * src/remove.c: Likewise. Signed-off-by: Jim Meyering <meyering@redhat.com>
2008-01-30Improve "rmdir --ignore-fail-on-non-empty"Jim Meyering
* 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 <http://bugs.debian.org/363011> via Bob Proulx. * NEWS: Mention the improvement.
2007-12-09"rm" as root would fail to unlink a non-directory on OS X 10.4.xJim Meyering
* src/remove.c (remove_entry) ["can unlink directories"]: Fix a mistakenly reversed condition. * NEWS: Mention this bug fix. Reported by Pieter Bowman.
2007-11-18Remove unused parameter in remove.c.Jim Meyering
* src/remove.c (fd_to_subdirp): Remove unused parameter. (remove_cwd_entries, remove_dir): Update callers.
2007-10-08When forming a truncated name, use the "[...]" prefix even forJim Meyering
an extremely long name in the current directory. * src/remove.c (full_filename_): Rename a local variable. Use two separate "truncated" variables, in case the second call to right_justify does not indicate any truncation -- which would happen only if the single component FILENAME were longer than 511 bytes and DIR_NAME were empty.
2007-10-08rm could malfunction under unusual circumstances:Jim Meyering
When operating on a relative name longer than 511 bytes, and (when either processing a directory that is neither writable nor readable (but still searchable) or when determining whether to prompt), and encountering an ENOMEM error while forming the file name, rm would operate on a truncated-to-511-byte name starting with "[...]" rather than the intended one. * NEWS: Describe the bugs. * src/remove.c: Correct two misuses of full_filename: (full_filename0, xfull_filename): New functions. (full_filename_): Rewrite to use full_filename0. (AD_pop_and_chdir): Use xfull_filename, not full_filename. (write_protected_non_symlink): Likewise.
2007-10-07Don't let a helper function modify errno.Jim Meyering
* src/remove.c (full_filename_): Save and restore errno. Spotted by Bruno Haible.
2007-10-05Make a failing cross-partition mv give a sensible diagnostic.Jim Meyering
A cross-partition move of a file in a sticky tmpdir and owned by another user would evoke an invalid diagnostic after copying it: mv: cannot remove `x': Operation not permitted Either of the following (mv.c, remove.c) changes would fix the bug by itself. I think it's slightly better to use both; the added cost is minimal: mv: an extra lstat-per-mv-cmdline-arg-that-goes-cross-partition, rm: an extra lstat-per-unlink-that-fails-w/EPERM. * src/remove.c (remove_entry): Also lstat the file upon EPERM. * src/mv.c (rm_option_init): Initialize root_dev_ino just as is done in rm, so that a cross-partition invoked remove.c:rm call works the same way as one invoked from the command-line use of "rm". That setting of root_dev_ino makes rm() do the equivalent of an additional lstat for each argument, which in turn gives rm enough information to issue the right diagnostic. * tests/mv/sticky-to-xpart (version): New file. Test for the above. * tests/mv/Makefile.am (TESTS): Add sticky-to-xpart. Arrange for "make check-root" to run the new root-only test. * tests/Makefile.am (tb): New target, to run the new root-only test. (all_t): Add tb. * src/c99-to-c89.diff: Adjust offsets.
2007-09-22rm: give a sensible diagnostic when failing to remove a symlinkJim Meyering
On some systems (those with openat et al), when rm would fail to remove a symlink, it would fail with the misleading diagnostic, "Too many levels of symbolic links". * NEWS: Mention the bug fix. * src/remove.c (is_nondir_lstat): New function. (remove_entry): Use it to catch failed-to-remove symlink (and any other non-dir) here so that we don't fall through and try to treat it as directory, which -- with a symlink -- would provoke the bogus ELOOP failure. * tests/rm/fail-eacces: Add a test for the above. * src/c99-to-c89.diff: Adjust offsets.
2007-09-22rm: fix a tiny, nearly inconsequential bug.Jim Meyering
Don't perform a "."-relative lstat, when the file in question may well not be in ".". Although this is a bug, a few attempts to exercise it on a linux-2.6.22 system failed. You probably need a pre-openat system to trigger the failure. The consequence of this bug would be a lower-quality diagnostic upon failed dir removal. * src/remove.c (is_dir_lstat): Add a parameter, fd_cwd. Use it instead of hard-coding AT_FDCWD. (remove_entry): Call is_dir_lstat with fd_cwd. Signed-off-by: Jim Meyering <jim@meyering.net>
2007-08-22Change "rm --verbose -r a//" not to print extra slashes in a///bJim Meyering
* src/remove.c (push_dir): Don't copy trailing slashes onto the stack. Reported by François Pinard. * tests/rm/v-slash: New file. Test for the above change. * tests/rm/Makefile.am (TESTS): Add v-slash.
2007-07-23Update all copyright notices to use the newer form.Jim Meyering
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