[BusyBox] cp -d support

Matt Kraai kraai at alumni.carnegiemellon.edu
Fri Apr 20 19:06:34 UTC 2001


On Fri, Apr 20, 2001 at 12:52:09PM -0600, Erik Andersen wrote:
> On Fri Apr 20, 2001 at 11:40:05AM -0700, Matt Kraai wrote:
> > I'm rewriting cp.  I've pretty much finished, except for the -d
> > option.  Do people actually use this?  If you use -a, you use it
> > indirectly.  Speak now, or forever hold your peace (piece?).  For
> > those who don't know (I didn't), -d copies symlinks themselves
> > rather than the thing linked to.
> 
> I just use 'cp -a' when I want to do that...

Since -a reduces to -dpR, I guess I should ask how often -a is
used.

> BTW, are you splitting cp and mv apart?

I plan to.  I haven't started on mv though.


Semi-related, you can use the attached script to put your favorite
cp through its paces (according to SUSv2).  You can run it with

BB=<path_to_busybox> sh ./test-cp

The current BusyBox produces the following results:

PASS: Copy empty file.
PASS: Copy small file.
PASS: Copy large file.
FAIL: Copy empty directory.
FAIL: Copy non-empty directory.
PASS: Copy file to directory.
PASS: Copy multiple files.
PASS: Preserves file permissions.
FAIL: Applies umask to file permissions.

My new implementation passes all of the tests (sound of me patting
myself on the back (ow, that hurts)).  So does GNU's.  If any one
wants to contribute more test cases, please send them to me.
Especially helpful would be -d and -a ones, since their behavior
isn't specified in SUSv2.

I'm eventually planning to turn this into a greg testsuite, to
prevent regressions (like those currently plaguing the Debian
boot-floppies).  Also, it would be really nice if people fixing
bugs could send in similar testcases to prevent future
regressions.

Matt
-------------- next part --------------
#!/bin/sh -e

# Copy empty file.
touch src
$BB cp src dest
if cmp src dest; then
	echo PASS: Copy empty file.
else
	echo FAIL: Copy empty file.
fi
rm -f src dest

# Copy small file.
echo Small file. > src
$BB cp src dest
if cmp src dest; then
	echo PASS: Copy small file.
else
	echo FAIL: Copy small file.
fi
rm -f src dest

# Copy large file.
echo EOF | dd of=src count=1 bs=1024 seek=1024 2>/dev/null
$BB cp src dest
if cmp src dest; then
	echo PASS: Copy large file.
else
	echo FAIL: Copy large file.
fi
rm -f src dest

# Copy empty directory.
mkdir src
$BB cp -R src dest
if test -d dest; then
	echo PASS: Copy empty directory.
else
	echo FAIL: Copy empty directory.
fi
rm -rf src dest

# Copy non-empty directory.
mkdir src
touch src/src1
$BB cp -R src dest
if test -d dest -a -f dest/src1; then
	echo PASS: Copy non-empty directory.
else
	echo FAIL: Copy non-empty directory.
fi
rm -rf src dest

# Copy file to directory.
touch src
mkdir dest
$BB cp src dest
if test -f dest/src; then
	echo PASS: Copy file to directory.
else
	echo FAIL: Copy file to directory.
fi
rm -rf src dest

# Copy multiple files.
touch src1
touch src2
mkdir dest
$BB cp src1 src2 dest
if test -f dest/src1 -a -f dest/src2; then
	echo PASS: Copy multiple files.
else
	echo FAIL: Copy multiple files.
fi
rm -rf src1 src2 dest

# Preserves file permissions.
old_umask=`umask -p`
umask 0
touch src
chmod 777 src
$BB cp src dest
if test x`ls -l src | awk '{print $1}'` = x`ls -l dest | awk '{print $1}'`; then
	echo PASS: Preserves file permissions.
else
	echo FAIL: Preserves file permissions.
fi
$old_umask
rm -rf src dest

# Applies umask to file permissions.
old_umask=`umask -p`
umask 0070
touch src
chmod 777 src
$BB cp src dest
if test x`ls -l dest | awk '{print $1}'` = x-rwx---rwx; then
	echo PASS: Applies umask to file permissions.
else
	echo FAIL: Applies umask to file permissions.
fi
$old_umask
rm -rf src dest


More information about the busybox mailing list