summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-04-22 07:35:20 +0000
committerJim Meyering <jim@meyering.net>2002-04-22 07:35:20 +0000
commit8fd6feded96d7446631d4d88a889e50d76f46682 (patch)
tree4c52d5d4c5363b7d4227a9cebf15930aa4908bdf
parentc175e3f6c86206b676658c181556fc9b15f25f88 (diff)
downloadcoreutils-8fd6feded96d7446631d4d88a889e50d76f46682.tar.xz
(rm, remove_init, remove_fini): Don't use or even
initialize the active_dir_map unless --recursive (-r) is specified.
-rw-r--r--src/remove.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/remove.c b/src/remove.c
index c9f246ad4..53501b707 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -845,7 +845,7 @@ rm (struct File_spec *fs, int user_specified_name,
}
#ifdef ENABLE_CYCLE_CHECK
- if (S_ISDIR (filetype_mode))
+ if (x->recursive && S_ISDIR (filetype_mode))
{
struct active_dir_ent *old_ent;
struct active_dir_ent *new_ent;
@@ -906,18 +906,19 @@ The following two directories have the same inode number:\n"));
status = remove_dir (fs, need_save_cwd, x, cwd_dev_ino);
#ifdef ENABLE_CYCLE_CHECK
- {
- struct active_dir_ent tmp;
- struct active_dir_ent *old_ent;
-
- /* Remove this directory from the active_dir_map. */
- tmp.st_ino = fs->st_ino;
- assert (fs->have_device);
- tmp.st_dev = fs->st_dev;
- old_ent = hash_delete (active_dir_map, &tmp);
- assert (old_ent != NULL);
- free (old_ent);
- }
+ if (active_dir_map)
+ {
+ struct active_dir_ent tmp;
+ struct active_dir_ent *old_ent;
+
+ /* Remove this directory from the active_dir_map. */
+ tmp.st_ino = fs->st_ino;
+ assert (fs->have_device);
+ tmp.st_dev = fs->st_dev;
+ old_ent = hash_delete (active_dir_map, &tmp);
+ assert (old_ent != NULL);
+ free (old_ent);
+ }
#endif
return status;
@@ -925,16 +926,18 @@ The following two directories have the same inode number:\n"));
}
void
-remove_init (void)
+remove_init (struct rm_options const *x)
{
/* Initialize dir-stack obstacks. */
obstack_init (&dir_stack);
obstack_init (&len_stack);
#ifdef ENABLE_CYCLE_CHECK
- active_dir_map = hash_initialize (ACTIVE_DIR_INITIAL_CAPACITY, NULL,
- hash_active_dir_ent,
- hash_compare_active_dir_ents, free);
+ if (x->recursive)
+ active_dir_map
+ = hash_initialize (ACTIVE_DIR_INITIAL_CAPACITY, NULL,
+ hash_active_dir_ent,
+ hash_compare_active_dir_ents, free);
#endif
}
@@ -942,7 +945,8 @@ void
remove_fini (void)
{
#ifdef ENABLE_CYCLE_CHECK
- hash_free (active_dir_map);
+ if (active_dir_map)
+ hash_free (active_dir_map);
#endif
obstack_free (&dir_stack, NULL);