summaryrefslogtreecommitdiff
path: root/src/remove.c
AgeCommit message (Collapse)Author
2003-11-09Include "root-dev-ino.h".Jim Meyering
(remove_cwd_entries): Remove now-obsolete FIXME comment. (remove_dir): Support rm's new --preserve-root option.
2003-09-08Add a comment.Jim Meyering
2003-09-07(D_INO, ENABLE_CYCLE_CHECK) [D_INO_IN_DIRENT]:Jim Meyering
Don't define. These symbols are no longer used.
2003-07-27(prompt) [! recursive]: Don't prompt about unwritableJim Meyering
directories, as required by POSIX. Reported by Karl Berry.
2003-07-12(remove_dir): Give a diagnostic upon failed save_cwd,Jim Meyering
now that that function no longer calls `error'.
2003-07-12It appears that the `#pragma alloca' included via "system.h" isJim Meyering
adequate, since join.c uses alloca, yet lacked an in-file #pragma. Remove `#pragma alloca'.
2003-05-04(HAVE_WORKING_READDIR): Define to 0 if not defined.Jim Meyering
(IF_READDIR_NEEDS_REWINDDIR): Remove. (remove_cwd_entries): Rewrite to avoid IF_READDIR_NEEDS_REWINDDIR, which was a bit weird because it couldn't be emulated by a function.
2003-05-02Work around nasty readdir bug with Darwin6.5 and hfs file system.Jim Meyering
(IF_READDIR_NEEDS_REWINDDIR): Define. [! HAVE_WORKING_READDIR] (remove_cwd_entries): If readdir has just returned NULL and there has been at least one successful unlink or rmdir call since the opendir or previous rewinddir, then call rewinddir and reiterate the loop.
2003-05-02Factor out common code.Jim Meyering
(readdir_ignoring_dotdirs): New function. (is_empty_dir): Use it here. (remove_cwd_entries): Use it here.
2003-04-13(is_empty_dir): Don't closedir (NULL).Jim Meyering
2003-03-30(is_empty_dir): Don't let a failing closedirJim Meyering
clobber errno. Spotted by Arnold Robbins.
2003-03-16(rm): Put two local variables in static storage,Jim Meyering
so they can't be clobbered by the potential longjmp.
2003-03-09(AD_stack_pop): Cast sizeof... to int before changing its sign.Jim Meyering
This avoids a warning from gcc on 64-bit systems. (pop_dir): Reverse order of sign change and cast, to be consistent with the above.
2003-03-04(AD_pop_and_chdir): Call error here, now that restore_cwd no longer does it.Jim Meyering
2003-03-03(remove_cwd_entries): Include the full filename ofJim Meyering
the offending file, not just the basename.
2003-03-03(remove_cwd_entries) [!ROOT_CAN_UNLINK_DIRS]: Give anJim Meyering
accurate diagnostic when failing to remove a file owned by some other user. Reported by Ivo Timmermans via Michael Stone. This fixes Debian bug# 178471.
2003-02-14Include "euidaccess.h".Jim Meyering
Remove declaration of euidaccess.
2003-01-21(remove_entry) [ROOT_CAN_UNLINK_DIRS && HAVE_STRUCT_DIRENT_D_TYPE]: If a fileJim Meyering
has d_type == DT_UNKNOWN it may still be a directory -- or not (e.g., with FreeBSD on an NFS-mounted file system), so resort to calling lstat to find out.
2003-01-20Rename type: DS -> Dirstack_state.Jim Meyering
2003-01-20Remove some unnecessary parentheses.Jim Meyering
2003-01-07tweak commentJim Meyering
2003-01-07add a commentJim Meyering
2003-01-04rm could be tricked into mistakenly reporting a cycle.Jim Meyering
* src/remove.c: [cycle_check_state]: New global. (remove_cwd_entries): Adapt to new semantics of cycle_check. (rm): Call cycle_check_init and cycle_check_free for each file. When rm detects a cycle, don't abort the entire command, but rather just the affected command line argument. * src/remove.c: Include <setjmp.h> (struct dirstack_state) [current_arg_jumpbuf]: New member. (remove_cwd_entries): Call longjmp if we detect a cycle. (rm): Call setjmp here. * src/remove.c (cycle_check, is_power_of_two): Remove functions. Instead, include cycle-check.h and use it.
2003-01-04Don't include trailing /. in diagnostics about directories.Jim Meyering
(full_filename_): When FILENAME is just `.' and there is a nonempty directory-name part, don't append `/.'.
2003-01-04(remove_cwd_entries): Fix typos in comment.Jim Meyering
2003-01-04(struct dirstack_state): Define.Jim Meyering
To be used in place of these file-scoped globals ... (dir_stack, len_stack, Active_dir): Remove globals. (ds_init, ds_free): New functions. (full_filename): Define. (full_filename_): Rename from full_filename. Begin to make AD_* functions more generic. (AD_push_initial): Don't set status to RM_OK here. (AD_push): Likewise. (AD_INIT_OTHER_MEMBERS): Define. (remove_dir): Define the `status' member manually after each call to AD_push or AD_push_initial.
2003-01-04[S_ISLNK]: Don't define. It's already defined in sys2.h.Jim Meyering
2002-12-15Remove all uses of `PARAMS'.Jim Meyering
2002-12-15(PARAMS): Remove definition.Jim Meyering
2002-10-05(remove_entry) [ROOT_CAN_UNLINK_DIRS]: With `rm -i DIR',Jim Meyering
don't recurse into directory, DIR.
2002-09-06(prompt): Change comment to give a better note to translators.Jim Meyering
2002-08-29(is_empty_dir): Detect and diagnose readdir failures.Jim Meyering
Always close directory handle.
2002-08-29(remove_cwd_entries): Use closedir (not CLOSEDIR) when ignoring any return ↵Jim Meyering
value.
2002-08-29(remove_cwd_entries): Detect and diagnose readdirJim Meyering
failures. On some systems (at least EMC Celerra and Solaris5.8), this appears to be necessary.
2002-08-28(remove_cwd_entries): Use CLOSEDIR, not closedir.Jim Meyering
Give a diagnostic and fail if closedir fails.
2002-07-22rm would prompt for non-dangling symlinksJim Meyering
(prompt): When not interactive, don't prompt for a symlink.
2002-07-14Under some circumstances, rm would fail due to a lack ofJim Meyering
permissions, but give a misleading diagnostic like this: rm: cannot chdir from `.' to `foo': Not a directory (remove_dir): Detect the case in which unlinking a non-directory fails with EPERM, and give an appropriate diagnostic.
2002-07-04(prompt): Fix test for write-protectedness to alsoJim Meyering
check errno == EACCES. Otherwise, `rm dangling-symlink' would mistakenly prompt.
2002-06-29(AD_mark_current_as_unremovable): Replace dead code with an assertion.Jim Meyering
2002-06-25(prompt): Add a comment to help translators workJim Meyering
around the problem of making the translations of the adjective `write-protected' and the corresponding run-time-variable noun (e.g., file, directory, symlink, etc.) consistent. From Paul Eggert.
2002-06-12(rm): Fix typo in assertion.Jim Meyering
2002-06-07(remove_entry): Use DT_IS_DIR only ifJim Meyering
HAVE_STRUCT_DIRENT_D_TYPE is defined.
2002-06-02Merge in all changes from no-recursion branch.Jim Meyering
* src/remove.c (enum Ternary): Define type. (prompt): Add a parameter. Adjust callers. (remove_entry): Attempt rmdir here, only if a directory is `known' to be empty. Significant rework. (remove_dir): Propagate failure `up' also when rmdir fails. In interactive mode, prompt only once about an empty directory. * src/remove.c (enum Prompt_action): Define. (prompt): Two new parameters. Adjust all callers. Performance. * src/remove.c (remove_entry) [!ROOT_CAN_UNLINK_DIRS]: Don't call rmdir here. * src/remove.c (AD_pop_and_chdir): Don't use errno (it's not valid) in diagnostic for changed dev/ino. (remove_entry): Tweak diagnostic. * src/remove.c (ROOT_CAN_UNLINK_DIRS): Define. (AD_pop_and_chdir): Propagate status as we traverse back `up' the tree. (DO_UNLINK, DO_RMDIR): Define. (remove_entry) [ROOT_CAN_UNLINK_DIRS]: Add code so this works also on systems where root can use `unlink' to remove directories. * src/remove.c: Include file-type.h. Include file type in prompt when asking whether to remove file. Based on a patch from Paul Eggert. * src/remove.c (prompt): Add comment. * src/remove.c (remove_dir): Fix another (known) leak. * src/remove.c (hash_freer): New function. (AD_mark_helper): Use it. (AD_mark_as_unremovable): xstrdup the filename argument. (remove_dir): Free directory name. * src/remove.c (remove_entry): Fail also when trying to remove a directory without the --recursive option. Change a diagnostic, s/unlink/remove/, now that it can apply also to a directory. * src/remove.c (is_empty_dir): New function. (prompt): New function, factored out of... (remove_entry): ...here. Call it. (remove_dir): Call prompt before rmdir. * src/remove.c (remove_entry): Add support for prompting (e.g., -i). * src/remove.h (UPDATE_STATUS): New macro. * src/remove.c [AD_ent] (status): New member. This lets us propagate the status from a subdirectory to its parent via AD_pop_and_chdir. (AD_push_initial): Set it. (AD_push): Likewise. (remove_cwd_entries): Change return type to enum RM_status, and adjust all callers. (rm): Use UPDATE_STATUS rather than open-coding it. * src/remove.c (remove_entry): New function, factored out of... (remove_cwd_entries): ...here, and... (rm_1): ...here. * src/remove.c (remove_cwd_entries): Add support for --verbose. (remove_dir): Likewise. (rm_1): Likewise. * src/remove.c (rm): Free cwd_state, if necessary. * src/remove.c (rm_1): Remove now useless (always true) user_specified_name parameter. Adjust sole caller. * src/remove.c (rm): New function. This interface allows one to remove multiple arguments at a time. This is important in that it allows us to hide the remove_init/remove_fini functions and the cwd_state parameter. (rm_1): Renamed from rm. (remove_init, remove_fini): Remove functions. Each body is now part of `rm'.
2002-05-03Add FIXME comment.Jim Meyering
2002-04-27(cycle_check): Add a comment.Jim Meyering
2002-04-27(cycle_check): New function containing code factoredJim Meyering
out of remove_dir. The sole difference is that upon detecting a cycle, rm now dies unconditionally. Before, in interactive mode, it would ask the user whether to continue. (remove_dir): Call cycle_check.
2002-04-25Remove hash table, active_dir_map, used to detect directory cycles.Jim Meyering
Instead, detect them lazily with just O(1) memory. Suggestion from Andi Kleen. (is_power_of_two): New function. (print_nth_dir, make_active_dir_ent): Remove functions. (hash_active_dir_ent, hash_compare_active_dir_ents): Likewise. (remove_dir): Check for cycles here, ... (rm): ... and don't check for cycles here. (rm): Call fspec_get_full_mode here, rather than fspec_get_filetype_mode. We want to get the dev/ino earlier, and at the same time as when we get the file type, to avoid the risk that an attacker would change e.g. a directory to a symlink before we record its dev/ino.
2002-04-22(rm): Call exit with EXIT_FAILURE, not `1'.Jim Meyering
2002-04-22(rm, remove_init, remove_fini): Don't use or evenJim Meyering
initialize the active_dir_map unless --recursive (-r) is specified.
2002-03-10* src/copy.c (copy_reg): Use a more concise diagnostic forJim Meyering
reporting replaced files. This avoids a bug in the code, which mishandled ino_t wider than long. * src/remove.c (remove_dir): Likewise, twice.