mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-14 07:46:28 +02:00
* 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.
95 lines
2.9 KiB
C
95 lines
2.9 KiB
C
/* Remove directory entries.
|
|
|
|
Copyright (C) 1998, 2000, 2002, 2003-2009 Free Software Foundation, Inc.
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
#ifndef REMOVE_H
|
|
# define REMOVE_H
|
|
|
|
# include "dev-ino.h"
|
|
|
|
enum rm_interactive
|
|
{
|
|
/* Start with any number larger than 1, so that any legacy tests
|
|
against values of 0 or 1 will fail. */
|
|
RMI_ALWAYS = 3,
|
|
RMI_SOMETIMES,
|
|
RMI_NEVER
|
|
};
|
|
|
|
struct rm_options
|
|
{
|
|
/* If true, ignore nonexistent files. */
|
|
bool ignore_missing_files;
|
|
|
|
/* If true, query the user about whether to remove each file. */
|
|
enum rm_interactive interactive;
|
|
|
|
// FIXME: remove
|
|
/* If true, do not traverse into (or remove) any directory that is
|
|
on a file system (i.e., that has a different device number) other
|
|
than that of the corresponding command line argument. Note that
|
|
even without this option, rm will fail in the end, due to its
|
|
probable inability to remove the mount point. But there, the
|
|
diagnostic comes too late -- after removing all contents. */
|
|
bool one_file_system;
|
|
|
|
/* If true, recursively remove directories. */
|
|
bool recursive;
|
|
|
|
/* Pointer to the device and inode numbers of `/', when --recursive
|
|
and preserving `/'. Otherwise NULL. */
|
|
struct dev_ino *root_dev_ino;
|
|
|
|
/* If nonzero, stdin is a tty. */
|
|
bool stdin_tty;
|
|
|
|
/* If true, display the name of each file removed. */
|
|
bool verbose;
|
|
|
|
/* If true, treat the failure by the rm function to restore the
|
|
current working directory as a fatal error. I.e., if this field
|
|
is true and the rm function cannot restore cwd, it must exit with
|
|
a nonzero status. Some applications require that the rm function
|
|
restore cwd (e.g., mv) and some others do not (e.g., rm,
|
|
in many cases). */
|
|
bool require_restore_cwd;
|
|
};
|
|
|
|
enum RM_status
|
|
{
|
|
/* These must be listed in order of increasing seriousness. */
|
|
RM_OK = 2,
|
|
RM_USER_DECLINED,
|
|
RM_ERROR,
|
|
RM_NONEMPTY_DIR
|
|
};
|
|
|
|
# define VALID_STATUS(S) \
|
|
((S) == RM_OK || (S) == RM_USER_DECLINED || (S) == RM_ERROR)
|
|
|
|
# define UPDATE_STATUS(S, New_value) \
|
|
do \
|
|
{ \
|
|
if ((New_value) == RM_ERROR \
|
|
|| ((New_value) == RM_USER_DECLINED && (S) == RM_OK)) \
|
|
(S) = (New_value); \
|
|
} \
|
|
while (0)
|
|
|
|
extern enum RM_status rm (char *const *file, struct rm_options const *x);
|
|
|
|
#endif
|