summaryrefslogtreecommitdiff
path: root/src/remove.c
AgeCommit message (Collapse)Author
2011-01-11rm: ignore errno related to invalid file namesNadav Har'El
* src/remove.c (nonexistent_file_errno): Also skip EINVAL and EILSEQ, for at least smbfs rejection of '*' in file names. * NEWS: Mention the fix.
2011-01-07maint: suppress some clang scan-build warningsPádraig Brady
* src/pr.c (char_to_clump): Remove a dead store. * src/remove.c (fts_skip_tree): Likewise. * src/sort.c (key_warnings): Likewise. (sort): Suppress an uninitialized pointer warning.
2011-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2010-12-28coreutils: keep lines within 80-column limitsPaul Eggert
* cfg.mk (LINE_LEN_MAX, FILTER_LONG_LINES): New macros. (sc_long_lines): New rule. * HACKING: Use shorter URLs to the same material. * doc/Makefile.am, doc/coreutils.texi, m4/boottime.m4: * man/help2man, man/stdbuf.x, src/Makefile.am, src/cat.c, src/copy.c: * src/cp.c, src/dd.c, src/df.c, src/du.c, src/groups.c, src/install.c: * src/ls.c, src/md5sum.c, src/mv.c, src/od.c, src/pinky.c, src/ptx.c: * src/readlink.c, src/remove.c, src/rmdir.c, src/setuidgid.c: * src/sort.c, src/tail.c, src/touch.c, tests/Coreutils.pm: * tests/cp/existing-perm-race, tests/cp/perm, tests/cp/preserve-gid: * tests/du/2g, tests/du/long-from-unreadable, tests/init.sh: * tests/install/basic-1, tests/ls/nameless-uid: * tests/ls/readdir-mountpoint-inode, tests/misc/chroot-credentials: * tests/misc/cut, tests/misc/date, tests/misc/join, tests/misc/md5sum: * tests/misc/sha1sum, tests/misc/sha224sum, tests/misc/sort: * tests/misc/sort-continue, tests/misc/sort-files0-from: * tests/misc/sort-rand, tests/misc/stdbuf, tests/misc/tr: * tests/misc/uniq, tests/mv/atomic, tests/mv/part-fail: * tests/mv/part-symlink, tests/mv/sticky-to-xpart, tests/pr/pr-tests: * tests/rm/fail-2eperm, tests/rm/interactive-always: Reformat to fit within 80 columns. * doc/Makefile.am (BAD_POSIX_PERL): New macro. * doc/coreutils.texi: Reword slightly, to make menus and index lines shorter. * src/md5sum.c: Redo --help output so that it fits within 79 columns, since that's a bit more portable and all the other --help strings fit in 79 columns.
2010-03-10remove: without -f, avoid unnecessary-expense/issues with euidaccessJim Meyering
* src/remove.c (write_protected_non_symlink): If faccessat fails, return 1 or -1 directly, rather than falling back on euidaccess*.
2010-02-15remove.c: remove three unnecessary #include directivesJim Meyering
* src/remove.c: Don't include hash.h, hash-pjw.h or obstack.h. They have been unused since the fts rewrite.
2010-01-01maint: update all FSF copyright year lists to include 2010Jim Meyering
Use this command: git ls-files | grep -v COPYING \ | xargs env UPDATE_COPYRIGHT_USE_INTERVALS=1 \ build-aux/update-copyright
2009-12-19rm: fix --one-file-system regression due to fts conversionPádraig Brady
* src/remove.c (rm_fts): Fix incorrect comparison of device and inode numbers. * tests/rm/one-file-system2: Add a separate test so that it can be run as a normal user (It doesn't need to mount). * tests/Makefile.am: Reference it. * NEWS: Mention the fix. Reported by Jan Larres.
2009-11-05maint: factor out cycle warning, now that du will use it, tooJim Meyering
* src/system.h (emit_cycle_warning): Define. Factored out of... * src/remove.c (rm_fts): ...here. Use the new macro.
2009-11-03rm -f: ignore EROFS when it's really ENOENTJim Meyering
rm -f must not print a diagnostic for a nonexistent file. However, most linux-based kernel unlinkat functions set errno to EROFS when the named file (regardless of whether it exists) would lie on a read-only file system. remove.c now performs an extra fstatat call in that case, to determine whether the file exists. * src/remove.c (excise): Map EROFS to ENOENT, if a file is nonexistent. Reported by Steven Drake in <http://savannah.gnu.org/bugs/?27923>. * NEWS (Changes in behavior): Mention it.
2009-09-11rm: avoid compiler warningEric Blake
* src/remove.c (rm_fts): Don't allow fall-through when assertions are disabled.
2009-09-11rm: use gnulib faccessatEric Blake
* bootstrap.conf (gnulib_modules): Add faccessat. Replace strdup with strdup-posix. * m4/jm-macros.m4 (coreutils_MACROS): Revert previous change, now that gnulib does it for us. * src/remove.c (write_protected_non_symlink): Use faccessat in more situations.
2009-09-11rm: improve efficiency of rm -r (without -f) from O(N^2) to O(N)Jim Meyering
where N is the depth of the deepest hierarchy rm is processing. * src/remove.c (write_protected_non_symlink): Use faccessat to avoid O(N)-per-entry cost of calling euidaccess. * m4/jm-macros.m4 (coreutils_MACROS): Check for faccessat. * NEWS (Improvements): Mention it.
2009-09-11build: placate gcc's new -Wskip-jump-initJim Meyering
* remove.c (rm_fts): Put braces around each of the two offending blocks. * configure.ac: Don't turn off -Wjump-misses-init. With the rewrite of remove.c, it is no longer needed.
2009-09-11rm: rewrite to use ftsJim Meyering
* remove.c: Don't include "unlinkdir.h"; no longer used. Do not include <setjmp.h> or "cycle-check.h". Likewise. Include "xfts.h". (dir_name, dir_len): Remove definitions. (CONSECUTIVE_READDIR_UNLINK_THRESHOLD): Likewise. (INODE_SORT_DIR_ENTRIES_THRESHOLD, NEED_REWIND, D_TYPE): Likewise. (struct dirstack_state, Dirstack_state): Likewise. (g_buf, g_n_allocated): Remove declarations. (hash_freer, hash_compare_strings, rm_malloc): Remove functions. (rm_free, push_dir, top_dir, pop_dir, right_justify): Likewise. (full_filename0, xfull_filename, full_filename_): Likewise. (AD_stack_height, AD_stack_top, AD_stack_pop, AD_stack_clear): Likewise. (obstack_init_minimal, ds_init, ds_clear, ds_free): Likewise. (AD_pop_and_chdir, AD_ensure_initialized, AD_mark_helper): Likewise. (AD_mark_as_unremovable, AD_mark_current_as_unremovable): Likewise. (AD_push_initial, AD_push, AD_push, AD_is_removable): Likewise. (write_protected_non_symlink): Change 3rd parameter from dirstack_state "ds" to full_name. (prompt): Adjust parameters. Now, state comes from FTS/FTSENT pair. Those replace fd_cwd and "ds". Remove "filename". Remove pdirent_type in favor of new "is_dir" parameter. Rename is_empty to is_empty_p. (DO_RMDIR, DO_UNLINK): Remove definitions. (remove_entry, fd_to_subdirp, compare_ino): Remove functions. (dirent_count, dirent_inode_sort_may_be_useful): Likewise. (preprocess_dir): Likewise. (fts_skip_tree, mark_ancestor_dirs, excise, rm_fts): New functions. (remove_cwd_entries, remove_dir, rm_1): Remove functions. (rm): Rewrite as a simple loop calling fts_read and dispatching each entry via rm_fts. * src/rm.c (main): Adapt to new signature of rm(). * bootstrap.conf (gnulib_modules): Remove unlinkdir, no longer used. * src/Makefile.am (sc_tight_scope): Also recognize an extern "enum" declaration. * tests/rm/empty-name: Adjust expected output to match new diagnostic. * NEWS (Improvements): Mention it.
2009-08-28build: avoid unused variable warnings on cygwinEric Blake
* src/copy.c (clone_file, copy_attr_by_fd, copy_attr_by_name): Mark up unused variables. * src/remove.c (dirent_inode_sort_may_be_useful): Likewise.
2009-08-25global: convert indentation-TABs to spacesJim Meyering
Transformed via this shell code: t=$'\t' git ls-files \ | grep -vE '(^|/)((GNU)?[Mm]akefile|ChangeLog)|\.(am|mk)$' \ | grep -vE 'tests/pr/|help2man' \ | xargs grep -lE "^ *$t" \ | xargs perl -MText::Tabs -ni -le \ '$m=/^( *\t[ \t]*)(.*)/; print $m ? expand($1) . $2 : $_'
2009-06-23maint: update all Copyright year lists to include 2009Jim Meyering
2009-04-07maint: Clarify ambiguous refs to Linux kernels or GNU/Linux systemsPádraig Brady
* README-prereq: s_linux_GNU/Linux_ or s_linux_Linux kernel_ * README-valgrind: ditto * src/chown-core.c: ditto * src/dd.c: ditto * src/df.c: ditto * src/ls.c: ditto * src/mv.c: ditto * src/pwd.c: ditto * src/remove.c: ditto * src/shred.c: ditto * src/stat.c: ditto * src/su.c: ditto * src/system.h: ditto * src/timeout.c: ditto * src/truncate.c: ditto
2008-10-21reflect gnulib's removal of lstat.hJim Meyering
* src/copy.h: Don't include "lstat.h". * src/ls.c: Likewise. * src/remove.c: Likewise. * src/rm.c: Likewise.
2008-10-19accommodate gnulib header removalsJim Meyering
* src/copy.c: Don't include "euidaccess.h" or "lchmod.h". * src/cp.c: Don't include "lchmod.h". * src/ls.c: Don't include "dirfd.h". * src/mkdir.c: Don't include "lchmod.h". * src/pwd.c: Don't include "dirfd.h". * src/remove.c: Don't include "dirfd.h" or "euidaccess.h". * src/test.c: Don't include "euidaccess.h". * gl/modules/getloadavg.diff: Adjust diff for changed context. * src/uptime.c (uptime): Remove declaration.
2008-10-17maint: avoid warnings due to attribute warn_unused_resultJim Meyering
Now that a (void) cast no longer suffices to ignore warnings from gcc about uses of functions marked with the warn_unused_result attribute, we need an alternative. For the record, here's one of the ignorable warnings: "copy.c:233: warning: ignoring return value of 'fchown', declared with attribute warn_unused_result" * bootstrap.conf (gnulib_modules): Import ignore-value. * src/copy.c: Include "ignore-value.h". (set_owner): Use ignore_value in place of "(void)" casts, to ignore lchown and fchown failures. * src/cp.c (re_protect): Likewise, to ignore lchown failure. * src/remove.c (preprocess_dir): Remove unnecessary "(void)" cast.
2008-10-06remove.c: avoid compile failure on OS/2Jim Meyering
* src/remove.c (dirent_inode_sort_may_be_useful): Guard also with "#if defined __linux__". Reported by Elbert Pol.
2008-10-02remove.c: allow compilation on cygwinEric Blake
* src/remove.c (dirent_inode_sort_may_be_useful) [!HAVE_STRUCT_DIRENT_D_TYPE]: Elide definition when there is no point in trying to use it.
2008-10-01remove.c: combine two helper functions, to avoid sign-extensionJim Meyering
* src/remove.c (fs_handles_readdir_ordered_dirents_efficiently): Remove function, so as not to have to worry about the type of statfs.f_type and sign extension. (dirent_inode_sort_may_be_useful): Adjust comment. Perform the switch directly on the struct.member here, instead. Andreas Schwab spotted the potential for a sign-extension bug, that happens not to bite for the S_* f_type values currently used.
2008-10-01rm: don't preprocess a directory on a file system of type tmpfs or nfsJim Meyering
The preprocessing phase is not necessary on tmpfs, and induces a 20% performance decrease when removing a 2M-entry directory. * src/remove.c (fs_handles_readdir_ordered_dirents_efficiently): (dirent_inode_sort_may_be_useful): New functions from gnulib/fts.c. They'll probably become a gnulib module -- eventually. (preprocess_dir): Use dirent_inode_sort_may_be_useful.
2008-09-27remove.c: avoid compiler warningEric Blake
* src/remove.c (compare_ino, dirent_count) [!HAVE_STRUCT_DIRENT_D_TYPE]: Mask declaration when unused. Signed-off-by: Eric Blake <ebb9@byu.net>
2008-09-27rm -r: avoid O(n^2) performance for a directory with very many entriesJim Meyering
This enhancement works around a problem that is specific to at least ext3 and ext4 file systems. With them, it would take hours to remove a two-million-entry directory. RAM-backed file systems (tmpfs) are not affected, since there is no seek penalty. * remove.c (rm_malloc, rm_free, compare_ino): New functions. (dirent_count, preprocess_dir): New function. [struct readdir_data]: New struct. (remove_cwd_entries): Call preprocess_dir. * tests/rm/ext3-perf: New file. Test for the performance fix. * NEWS: mention the new feature
2008-09-27remove.c: don't use xmalloc; don't let obstack call exit on failureJim Meyering
(obstack_chunk_alloc, obstack_chunk_free): Don't define. (top_dir): Param is no longer "const". Use malloc, not xmalloc, and call longjmp upon failed malloc. (obstack_init_minimal): New function. (ds_init): Don't use xmalloc. Instead, use caller-supplied buffer. Use obstack_specify_allocation_with_arg, not obstack_init, so that we control what happens upon allocation failure. Arrange for ds_free not to free uninitialized if/when any obstack_specify_allocation_with_arg allocation fails. (ds_free): Don't free DS, now that it's no longer malloc'd. (rm): Allocate DS on the stack. Arrange to handle ds_init allocation failure. step1
2008-09-19remove.c: move comment to right before string, so gettext will pick it upBenno Schulenberg
2008-09-19nohup, remove, tr: also gettextize the alternative messagesBenno Schulenberg
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>