-T option help text

2009-09-03 Thread James R. Van Zandt

Philip Rowlands wrote:
 On Sun, 30 Aug 2009, James R. Van Zandt wrote:
 
 
   For the help text, here are some alternatives:
 
 
   if DEST is a directory, then delete it first 
 
 
 This isn't what -T does. If DEST is an empty directory then it's
 overwritten with the rename(2) system call. Otherwise mv will fail
 e.g. if SOURCE isn't a directory or DEST is non-empty.

Let's see...

  vanzandt:/tmp$ date source
  vanzandt:/tmp$ mkdir dest
  vanzandt:/tmp$ mv -T source dest
  mv: cannot overwrite directory `dest' with non-directory
  vanzandt:/tmp$ rm -rf dest
  vanzandt:/tmp$ touch test
  vanzandt:/tmp$ mv -T source dest
  vanzandt:/tmp$ 
  
I agree my proposed help text is wrong.  However, I think the current
description in the info file is wrong too.  It says Do not treat the
last operand specially when it is a directory or a symbolic link to a
directory.  Yet, this is an example where mv fails when DEST is a
directory, and succeeds when it is a normal file.  So a directory *is*
treated differently.

The extended discussion on the Target directory page says:

 For example, when the command `mv /tmp/source /tmp/dest'
 succeeds, there is no guarantee that `/tmp/source' was renamed to
 `/tmp/dest': it could have been renamed to `/tmp/dest/source'
 instead, if some other process created `/tmp/dest' as a
 directory.  However, if `mv -T /tmp/source /tmp/dest' succeeds,
 there is no question that `/tmp/source' was renamed to
 `/tmp/dest'.

I read the last sentence as saying /tmp/source would get renamed as
/tmp/dest whether or not some other process had previously created
/tmp/dest as a directory.  The fact that it fails instead certainly
should be stated.  (To me it seems a much less useful behavior.)

- Jim Van Zandt








Re: -T option help text

2009-08-31 Thread Philip Rowlands

On Sun, 30 Aug 2009, James R. Van Zandt wrote:


For the help text, here are some alternatives:

   if DEST is a directory, then delete it first


This isn't what -T does. If DEST is an empty directory then it's 
overwritten with the rename(2) system call. Otherwise mv will fail e.g. 
if SOURCE isn't a directory or DEST is non-empty.



This is short, but doesn't handle the case of DEST being a
symbolic link

   if DEST is a directory, or a symbolic link to a directory, then delete it 
first


This isn't what -T does either. If DEST is a symlink it isn't 
deleted, merely clobbered by mv. It's the difference between


rename(file, DEST/file)  = 0
and
rename(file, DEST)   = 0

For the short --help description I'd try something like

disable special directory handling for DEST


Cheers,
Phil




-T option help text

2009-08-30 Thread James R. Van Zandt

Kamil Dudka wrote:
On Sunday 30 of August 2009 03:11:34 James R. Van Zandt wrote:
 ...(I'd first have to check the help printout to
 see that it's not -T I wanted after all.  Then check the info page,
 because the -T description is so unhelpful.  But that's a separate
 issue.)

 What exactly is unhelpful on the -T description? We'll be happy to
 improve the description if you come with something better.

The current help entry is:

  -T, --no-target-directorytreat DEST as a normal file

A long option is supposed to be more or less self documenting, but
this long option doesn't tell me anything.  I find myself asking No
target directory?  But there's *always* a target directory!

I find the help text pretty obscure too.  Of the various things DEST
could be besides a regular file (symbolic link, device, pipe...) what
would it mean to treat it as a regular file?  After reading the info
page, I have to admit that the help text is technically correct.
However, if it can't be understood without reading the info page, then
it is not doing its job.

For the help text, here are some alternatives:

if DEST is a directory, then delete it first

This is short, but doesn't handle the case of DEST being a
symbolic link

if DEST is a directory, or a symbolic link to a directory, then delete it 
first

correct but wordy

if DEST exists, then delete it first (even if it's a directory)

I prefer this.


I'd really like to change the long option too.  It should not be
saying there is no target directory but rather that the second
operand is not naming a target directory.  A couple possibilities:

  --rm-target-first
  --rm-dest-first

However, I am not really happy with either one.

   - Jim Van Zandt