Subject: "cp -R" (on 1.6.2) blows up on identical symlinks!?!?
To: NetBSD Userlevel Technical Discussion List <tech-userlevel@NetBSD.ORG>
From: Greg A. Woods <>
List: tech-userlevel
Date: 05/20/2004 20:44:08
I was trying to avoid having to de-install p5-perl-headers so I thought
I'd try forcing the install only to be tripped up by this:

/bin/cp -R /var/package-obj/devel/p5-perl-headers/work/h2ph/* /usr/pkg/lib/perl5/site_perl/5.6.1/alpha-netbsd
cp: cannot overwrite directory /usr/pkg/lib/perl5/site_perl/5.6.1/alpha-netbsd/machine with non-directory /var/package-obj/devel/p5-perl-headers/work/h2ph/machine

The trick here is that it's not a directory that's being overwritten --
it's a symlink to a directory:

$ ls -ld /var/package-obj/devel/p5-perl-headers/work/h2ph/machine 
lrwxr-xr-x  1 woods  wheel  5 May 20 20:21 /var/package-obj/devel/p5-perl-headers/work/h2ph/machine -> alpha

and it has the exact same target as the existing symlink:

$ ls -ld /usr/pkg/lib/perl5/site_perl/5.6.1/alpha-netbsd/machine  
lrwxr-xr-x  1 root  wheel  5 Feb 26 15:41 /usr/pkg/lib/perl5/site_perl/5.6.1/alpha-netbsd/machine -> alpha

This seems rather surprising at best, and perhaps undesirable as well.

Is this a bug?  Should '-P' have been used?  Would '-P' help?

I think '-P' should be used:

       * If the -R option was specified:

            * If none of the options -H, -L, nor -P were specified, it
              is unspecified which of -H, -L, or -P will be used as a

and if it works as SuSv3 says here then it should help too:

            * If the -P option was specified, cp shall copy any symbolic
              link specified as a source_file operand and any symbolic
              links encountered during traversal of a file hierarchy,
              and shall not follow any symbolic links.

unfortunately it doesn't seem to help:

/bin/cp -RP /var/package-obj/devel/p5-perl-headers/work/h2ph/* /usr/pkg/lib/perl5/site_perl/5.6.1/alpha-netbsd
cp: cannot overwrite directory /usr/pkg/lib/perl5/site_perl/5.6.1/alpha-netbsd/machine with non-directory /var/package-obj/devel/p5-perl-headers/work/h2ph/machine

Should I send-pr something about this?

						Greg A. Woods

+1 416 218-0098                  VE3TCP            RoboHack <>
Planix, Inc. <>          Secrets of the Weird <>