From fdc2da7165d93c8065365999341173ad2a818833 Mon Sep 17 00:00:00 2001 From: Krzysztof Goj Date: Sun, 22 Jan 2012 01:39:59 +0100 Subject: rm: new option --dir (-d) to remove empty directories 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. --- src/remove.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/remove.h') diff --git a/src/remove.h b/src/remove.h index 4eab2821f..f994517af 100644 --- a/src/remove.h +++ b/src/remove.h @@ -49,6 +49,9 @@ struct rm_options /* If true, recursively remove directories. */ bool recursive; + /* If true, remove empty directories. */ + bool remove_empty_directories; + /* Pointer to the device and inode numbers of '/', when --recursive and preserving '/'. Otherwise NULL. */ struct dev_ino *root_dev_ino; -- cgit v1.2.3-54-g00ecf