Subject: Re: bug#10837: bug of install program

From: Eric Blake <[email-masked]>
Date: Fri, 17 Feb 2012 11:50:17 -0700

tag 10837 notabug
thanks

On 02/17/2012 10:30 AM, 陈燕潘 wrote:
> Hi, I come across a problem, I don't whether it is a bug.
> Version of install is 7.1.

Thanks for the report.  Your install is a bit old; right now, the
current version is 8.15.  However, the behavior you are reporting is
intentional, and has not changed in the meantime.

> I have something look like this:
> opensuse113:/home/test_install # find 1/
> 1/
> 1/a
> 1/a/b
> 1/a/b/c
> 1/a/b/c/d.txt
> 1/a/b/c/d
> opensuse113:/home/test_install # find 2/
> 2/
> I want to copy everything in 1/a/b/c to 2/a/b/c. So I use the command with the option -D, but it doesn't work.
> opensuse113:/home/test_install # install -D 1/a/b/c/* 2/a/b/c
> install: target `2/a/b/c' is not a directory

Let's revisit the 'install --help' output, and see why:

Usage: install [OPTION]... [-T] SOURCE DEST
  or:  install [OPTION]... SOURCE... DIRECTORY
  or:  install [OPTION]... -t DIRECTORY SOURCE...
  or:  install [OPTION]... -d DIRECTORY...
...
In the first three forms, copy SOURCE to DEST or multiple SOURCE(s) to
the existing DIRECTORY, while setting permission modes and owner/group.
...
  -D                  create all leading components of DEST except the last,
                        then copy SOURCE to DEST

> 
> Wht not create the directory 2/a/b/c, then copy everying?

Note that you ended up invoking the second form (multiple source files,
to an existing directory), but that -D is only useful with the first
form (single source file, and a DEST that gets created with the same
contents as the single source).  That is, we intentionally treat the
DEST of form 1 differently than the DIRECTORY of form 2.

>  
> Looking forward to your reply.

I'd recommend that you split this into two steps, which will work now:

install -d 2/a/b/c && install 1/a/b/c/* 2/a/b/c

Or, you can propose a patch to make -D work with the second form (that
is, have it interact with a DIRECTORY by creating all elements, compared
to its current documentation of interacting only with a DEST where only
the leading directories, but not the last element, are created).  But
I'm not sure if such a patch would make matters more confusing.  Maybe
it's better to just propose a patch that rejects -D when using form 2,
rather than the current behavior of accepting -D only to fail because it
would create 2/a/b but not 2/a/b/c, and needs 2/a/b/c to exist as a
target directory.

But since such a patch is a wishlist for a minor improvement, rather
than an actual bug fix, I'm closing this bug for now.  We can reopen it
if needed, and you can feel free to add further comments even while the
bug is closed.

-- 
Eric Blake   [email-masked]    +1-919-301-3266
Libvirt virtualization library http://libvirt.org