summaryrefslogtreecommitdiff
path: root/src/remove.c
AgeCommit message (Collapse)Author
2016-01-01maint: update all copyright year number rangesPádraig Brady
Run "make update-copyright" and then... * gnulib: Update to latest with copyright year adjusted. * tests/init.sh: Sync with gnulib to pick up copyright year. * bootstrap: Likewise. * tests/sample-test: Adjust to use the single most recent year.
2015-11-04all: avoid quoting file names when possiblePádraig Brady
Quote file names using the "shell-escape" or "shell-escape-always" methods, which quote as appropriate for most shells, and better support copy and paste of presented names. The "always" variant is used when the file name is embedded in an error message with surrounding spaces. * cfg.mk (sc_error_shell_quotes): A new syntax check rule to suggest quotef() where appropriate. (sc_error_shell_always_quotes): Likewise for quoteaf(). * src/system.h (quotef): A new define to apply shell quoting when needed. I.E. when shell character or ':' is present. (quoteaf): Likewise, but always quote. * src/*.c: Use quotef() and quoteaf() rather than quote() where appropriate. * tests/: Adjust accordingly.
2015-01-01maint: update all copyright year number rangesPádraig Brady
Run "make update-copyright" and then... * tests/sample-test: Adjust to use the single most recent year. * tests/du/bind-mount-dir-cycle-v2.sh: Fix case in copyright message, so that year is updated automatically in future.
2014-04-16doc: improve remove prompt translator commentBenno Schulenberg
* src/remove.c (prompt): Explain where the difficulty with translating these two strings resides, and suggest an alternative: the one that Paul Eggert first proposed back in 2002, which seems fully resistant.
2014-01-02maint: update all copyright year number rangesBernhard Voelker
Run "make update-copyright", but then also run this, perl -pi -e 's/2\d\d\d-//' tests/sample-test to make that one script use the single most recent year number.
2013-11-21doc: enhance diagnostic when rm skips "." or ".." argumentsBernhard Voelker
The error diagnostic "rm: cannot remove directory: '.'" does not give the user a hint for the reason. Issue a clearer error message. * src/remove.c (rm_fts): Enhance the error diagnostic in the above case to emphasize that skipping is done deliberately. In the corresponding comment, mention that POSIX mandates this behavior. Likewise in the subsequent comment for skipping "/". * doc/coreutils.texi (rm invocation): In the paragraph describing the above behavior, mention that POSIX mandates it.
2013-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright", but then also run this, perl -pi -e 's/2\d\d\d-//' tests/sample-test to make that one script use the single most recent year number.
2012-09-19rm: be even more careful when using a replacement errno valueJim Meyering
* src/remove.c (excise): The change in commit v8.19-107-gccbd3f3 made the "rm -rf D" (for unreadable dir, D) diagnostic worse on Solaris 10: -rm: cannot remove 'D': Permission denied +rm: cannot remove 'D': File exists That happened because unlinkat would fail with EEXIST there, given an unreadable directory, which made the two tests, tests/rm/unread2 and tests/rm/unreadable fail. Accommodate the EEXIST case, too.
2012-09-05rm: be more careful when using a replacement errno valueJim Meyering
* src/remove.c (excise): Tighten the test for when we defer to an old errno value: instead of relying solely on an FTS_DNR (unreadable directory) failure, also test current and replacement errno values. This change would also have solved the problem addressed by commit v8.19-106-g57dd067. For more info, see http://bugs.gnu.org/12339#113
2012-09-05rm: avoid bogus diagnostic for a slash-decorated symlink-to-dirJim Meyering
These commands would evoke an invalid diagnostic: $ mkdir d && ln -s d s && env rm -r s/ rm: cannot remove 's': Too many levels of symbolic links remove.c was stripping trailing slashes from "s/" before passing the name to "rm". But a trailing slash may change the semantics, and thus should not be stripped. * src/remove.c (rm_fts): Do not strip trailing slashes. * tests/rm/v-slash.sh: Adapt to new expected output. * gnulib: Update to latest, for an improved fts.c that merely normalizes trailing slashes. Reported by Paul Eggert in discussion of http://bugs.gnu.org/12339
2012-08-23rm: fix the new --dir (-d) option to work with -iRob Day
* src/remove.c (prompt): Hoist the computation of is_empty, since we'll need it slightly earlier. Before, this function would arrange to fail with EISDIR when processing a directory without --recursive (-r). Adjust the condition to exempt an empty directory when --dir has been specified. Improve comments. * tests/rm/d-3: New file, to ensure that rm -d -i dir works. * tests/Makefile.am (TESTS): Add it. * NEWS (Bug fixes): Mention it. * THANKS.in: Update. Reported by Michael Price in http://bugs.gnu.org/12260
2012-08-16maint: fix comment grammar to placate make syntax-checkJim Meyering
* src/remove.c (rm_fts): s/can not/cannot/
2012-08-14rm: new option --dir (-d) to remove empty directoriesKrzysztof Goj
Add new option to rm (-d/--dir), which allows removal of empty directories, while still safely disallowing removal of non-empty ones. This improves compatibility with Mac OS X and BSD systems, which honor the -d option. * src/remove.c (rm_fts): Remove empty directories when requested. * src/remove.h (rm_options) [remove_empty_directories]: New member. * src/rm.c (long_opts, usage, main): Update usage and option parsing. (rm_option_init): Initialize the new member. * src/mv.c (rm_option_init): Initialize the new member. * tests/rm/d-1: New test case - successfully delete empty dir. * tests/rm/d-2: New test case - refuse to delete nonempty dir. * tests/Makefile.am (TESTS): Add them.
2012-07-20maint: rm: remove two more unused static inline functionsJoachim Schmitz
* src/remove.c (cache_stat_ok, is_nondir_lstat): Remove unused functions.
2012-07-20maint: rm: remove unused static-inlined functionsJoachim Schmitz
* src/remove.c (cache_statted, is_dir_lstat): Remove unused static-inlined functions. * THANKS.in: Remove my name from this list, now that (with this commit) it is included automatically. Copyright-paperwork-exempt: Yes
2012-01-27maint: use single copyright year rangeJim Meyering
Run "make update-copyright".
2012-01-09maint: src/*.[ch]: convert more `...' to '...'Jim Meyering
Run this (twice): git grep -E -l '`.+'\' src/*.[ch] \ |xargs perl -pi -e 's/`(.+?'\'')/'\''$1/'
2012-01-09maint: src/*.c: change remaining quotes (without embedded spaces)Jim Meyering
Run this (twice): git grep -E -l '`[^ ]+'\' src/*.c \ |xargs perl -pi -e 's/`([^ ]+'\'')/'\''$1/'
2012-01-01maint: update all copyright year number rangesJim Meyering
Run "make update-copyright".
2011-10-09rm: do not resort to stat'ing very long names even on deficient systemsJim Meyering
This change affects only systems that have neither *at function support nor the /proc/self/fd support required to emulate those *at functions. * src/remove.c (write_protected_non_symlink): Call faccessat unconditionally. Thus we no longer need euidaccess_stat, which was the sole function used here to operate on a full relative file name. Remove full_name parameter and update caller. * lib/euidaccess-stat.h: Remove file. * lib/euidaccess-stat.c: Likewise. * m4/euidaccess-stat.m4: Likewise. * po/POTFILES.in: Remove lib/euidaccess-stat.c. * m4/prereq.m4 (gl_PREREQ): Don't require gl_EUIDACCESS_STAT. Prompted by a report from Bruno Haible that the rm/deep-2 test was failing on HP-UX 11.31. See http://thread.gmane.org/gmane.comp.gnu.coreutils.general/1748
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