[PATCH] rm --directory (-d)
Hello again, I have finally completed my --directory (-d) feature, like the FreeBSD one. The directory option deletes a directory only if the directory in question is empty. This is a safer alternative to the recursive option is some cases where you don't want to delete unempty directories. I have documented the features. Although I am not the best technical writer, I hope that what I have done is adequate. One thing that I have neglected to do, intentionally, is to write an automated test. I am not skilled enough or confident enough in my Perl or shell scripting ability to write such a test. I would love to hear what I could have done better, or possibly what I have done wrong. Any comments on my code are very much appreciated. That is a big part of why I am doing this is to become a better programmer. Thank you, and with out further ado, here is the patch. >From 0dc91f3088b27053afe7db2c293ebaad38a51a68 Mon Sep 17 00:00:00 2001 From: Patrick W. Plusnick II Date: Fri, 5 Mar 2010 22:22:00 -0600 Subject: [PATCH] rm: add the --directory (-d) option that removes empty directories *doc/coreutils.texi: Added some documentation about the changes *src/remove.c: Changes are mostly in the rm_fts function under the FTS_D case. I added the proper conditions for the removal of only empty directories. *src/remove.h: I only added a flag to RM_option. *src/rm.c: I added facilities to set the directory (-d) flag. --- doc/coreutils.texi |8 src/remove.c | 48 ++-- src/remove.h |3 +++ src/rm.c |8 4 files changed, 61 insertions(+), 6 deletions(-) diff --git a/doc/coreutils.texi b/doc/coreutils.texi index fcee336..24732be 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -8393,6 +8393,14 @@ The program accepts the following options. Also see @ref{Common options}. @table @samp +...@item -d +...@itemx --directory +...@opindex -d +...@opindex --directory +Remove a directory only if it is empty. +Skipped if the @option{--recursive} (@option{-r} or @option{-R}) is +specified. + @item -f @itemx --force @opindex -f diff --git a/src/remove.c b/src/remove.c index b6cfc8e..3e6857f 100644 --- a/src/remove.c +++ b/src/remove.c @@ -274,7 +274,7 @@ prompt (FTS const *fts, FTSENT const *ent, bool is_dir, break; case DT_DIR: -if (!x->recursive) +if (!x->recursive && !x->directory) { write_protected = -1; wp_errno = EISDIR; @@ -472,7 +472,7 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x) switch (ent->fts_info) { case FTS_D:/* preorder directory */ - if (! x->recursive) + if (! x->recursive && ! x->directory) { /* This is the first (pre-order) encounter with a directory. Not recursive, so arrange to skip contents. */ @@ -507,19 +507,55 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x) return RM_ERROR; } } + /* The recursive option takes precedence over the directory option */ + if (x->recursive) +{ + Ternary is_empty_directory; + enum RM_status s = prompt (fts, ent, true /*is_dir*/, x, + PA_DESCEND_INTO_DIR, &is_empty_directory); + + if (s == RM_OK && is_empty_directory == T_YES) +{ + /* When we know (from prompt when in interactive mode) + that this is an empty directory, don't prompt twice. */ + s = excise (fts, ent, x, true); + fts_skip_tree (fts, ent); +} + + if (s != RM_OK) +{ + mark_ancestor_dirs (ent); + fts_skip_tree (fts, ent); +} + return s; +} + /* If the directory option is set, remove the directory + if it is empty. */ { Ternary is_empty_directory; enum RM_status s = prompt (fts, ent, true /*is_dir*/, x, - PA_DESCEND_INTO_DIR, &is_empty_directory); - + PA_REMOVE_DIR, &is_empty_directory); if (s == RM_OK && is_empty_directory == T_YES) { -/* When we know (from prompt when in interactive mode) - that this is an empty directory, don't prompt twice. */ s = excise (fts, ent, x, true); fts_skip_tree (fts, ent); } +else if (s == RM_USER_DECLINED) /* Get out of the if */ +; +/* The directory may still be empty */ +else if (is_empty_directory == T_UNKNOWN && + is_empty_dir (fts->fts_cwd_fd, ent->fts_accpath)) + { +s = excise (fts, ent, x, true); +fts_skip_tree (fts, ent); + } +else + { +s = RM_ERROR; +error (0, ENOTEMP
Re: install not atomic
On Sunday 28 February 2010 03:35:19 Ralf Wildenhues wrote: > Hello bug-coreutils readers, > > a recent GCC bug report[1] the GNU install program is not atomic; i.e., > when you > install file $dest & install file $dest > > then one of them may fail. For reproducability purposes, use several > large files, and call in a loop. > > I suppose it's fine for install to have this limitation, as it's > arguably a bug (or limitation) in the build system, and there is no > standard or documentation stating otherwise, but the behavior was > sufficiently surprising to me that I thought I'd write about it here > nonetheless. doesnt the same limitation exist in ln/mv/etc... ? touch a; while :; do (ln -f a f &) ; done and i'm not sure things can be "fixed" in the programs ... so documenting the limitation sounds like the only sane solution -mike signature.asc Description: This is a digitally signed message part.
Re: you are not going to be able to sort this by the fifth field.
EB> Except that you can specify overlapping keys. I find the idea of multiple EB> separate lines of underscores, one per key, much easier to follow in OK, any --debug=... is better than nothing.
Re: bug with head
According to François Civet on 3/5/2010 7:24 AM: > Dear bug reporter, > I found a bug with the head command. > while opening an ACSII file with the command: > head file * This command passes the name of all files in the current directory, including any binary files. > the interface of my gnome-terminal shows non-ASCII characters. To be expected, if any of those files had non-ASCII contents. But that does not make it a bug in head. Perhaps you wanted 'head file', rather than 'head file *'? -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
bug with head
Dear bug reporter, I found a bug with the head command. while opening an ACSII file with the command: head file * the interface of my gnome-terminal shows non-ASCII characters. my PC is under ubuntu 8.10 if you need some other information... please tell me with kind regards François Civet -- François Civet Doctorant IUEM - Domaines Océaniques Place Nicolas Copernic 29280 Plouzané, France tel +33(0)298498740 mob +33(0)674570278
Re: date command
Hi Erik, there is no TZ set. # date Fr Mär 5 13:59:12 UCT 2010 # date -u Fr Mär 5 13:59:18 UTC 2010 Lets see... OK, yes you are right its a typo in SuSe system setting: SUSE LINUX 10.1 (X86-64) tail /etc/sysconfig/clock ## Type:string(Europe/Berlin,Europe/London,Europe/Paris) ## ServiceRestart: boot.clock # # Timezone (e.g. CET) # (this will set /usr/lib/zoneinfo/localtime) # TIMEZONE="UCT" DEFAULT_TIMEZONE="Europe/Berlin" Thanks a lot for your help. Regards Bernd Eric Blake schrieb: > According to Bernd Fehling on 3/5/2010 6:04 AM: >> Hi all, >> >> while using the date command (date GNU coreutils 5.93) >> it reports e.g.: >> Fri Mar 5 13:01:52 UCT 2010 >> >> So why is it reporting UCT and not UTC ??? >> Is that a typo? > > Most likely, it is being inherited from $TZ in the environment: > > $ TZ=UTC date > Fri Mar 5 13:45:10 UTC 2010 > $ TZ=UCT date > Fri Mar 5 13:45:13 UCT 2010 > > If it is a typo in your environment, then check your configuration files > (such as ~/.bashrc...) for who might have been setting it wrongly in the > first place. >
Re: date command
According to Bernd Fehling on 3/5/2010 6:04 AM: > Hi all, > > while using the date command (date GNU coreutils 5.93) > it reports e.g.: > Fri Mar 5 13:01:52 UCT 2010 > > So why is it reporting UCT and not UTC ??? > Is that a typo? Most likely, it is being inherited from $TZ in the environment: $ TZ=UTC date Fri Mar 5 13:45:10 UTC 2010 $ TZ=UCT date Fri Mar 5 13:45:13 UCT 2010 If it is a typo in your environment, then check your configuration files (such as ~/.bashrc...) for who might have been setting it wrongly in the first place. -- Eric Blake ebl...@redhat.com+1-801-349-2682 Libvirt virtualization library http://libvirt.org signature.asc Description: OpenPGP digital signature
date command
Hi all, while using the date command (date GNU coreutils 5.93) it reports e.g.: Fri Mar 5 13:01:52 UCT 2010 So why is it reporting UCT and not UTC ??? Is that a typo? Regards Bernd