summaryrefslogtreecommitdiff
path: root/src/rm.c
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-07-12 18:15:23 +0200
committerJim Meyering <meyering@redhat.com>2009-09-11 14:08:51 +0200
commit4f73ecaf7def2a7bdc381eee2036f6539df01e7d (patch)
treed1affca9ff5c75e467b4c2b85ded6f329748d49d /src/rm.c
parent880a6e7723a9e222318ce065ee15968a1cbe1830 (diff)
downloadcoreutils-4f73ecaf7def2a7bdc381eee2036f6539df01e7d.tar.gz
rm: rewrite to use fts
* 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.
Diffstat (limited to 'src/rm.c')
-rw-r--r--src/rm.c34
1 files changed, 6 insertions, 28 deletions
diff --git a/src/rm.c b/src/rm.c
index 5995e46fd..6c3255198 100644
--- a/src/rm.c
+++ b/src/rm.c
@@ -14,32 +14,9 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-/* Written by Paul Rubin, David MacKenzie, and Richard Stallman.
- Reworked to use chdir and avoid recursion by Jim Meyering. */
-
-/* Implementation overview:
-
- In the `usual' case, RM saves no state for directories it is processing.
- When a removal fails (either due to an error or to an interactive `no'
- reply), the failure is noted (see description of `ht' in remove.c's
- remove_cwd_entries function) so that when/if the containing directory
- is reopened, RM doesn't try to remove the entry again.
-
- RM may delete arbitrarily deep hierarchies -- even ones in which file
- names (from root to leaf) are longer than the system-imposed maximum.
- It does this by using chdir to change to each directory in turn before
- removing the entries in that directory.
-
- RM detects directory cycles lazily. See lib/cycle-check.c.
-
- RM is careful to avoid forming full file names whenever possible.
- A full file name is formed only when it is about to be used -- e.g.
- in a diagnostic or in an interactive-mode prompt.
-
- RM minimizes the number of lstat system calls it makes. On systems
- that have valid d_type data in directory entries, RM makes only one
- lstat call per command line argument -- regardless of the depth of
- the hierarchy. */
+/* Initially written by Paul Rubin, David MacKenzie, and Richard Stallman.
+ Reworked to use chdir and avoid recursion, and later, rewritten
+ once again, to use fts, by Jim Meyering. */
#include <config.h>
#include <stdio.h>
@@ -358,7 +335,7 @@ main (int argc, char **argv)
}
size_t n_files = argc - optind;
- char const *const *file = (char const *const *) argv + optind;
+ char **file = argv + optind;
if (prompt_once && (x.recursive || 3 < n_files))
{
@@ -370,7 +347,8 @@ main (int argc, char **argv)
if (!yesno ())
exit (EXIT_SUCCESS);
}
- enum RM_status status = rm (n_files, file, &x);
+
+ enum RM_status status = rm (file, &x);
assert (VALID_STATUS (status));
exit (status == RM_ERROR ? EXIT_FAILURE : EXIT_SUCCESS);
}