]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
*** empty log message ***
authorJim Meyering <jim@meyering.net>
Sat, 12 Aug 2000 13:23:18 +0000 (13:23 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 12 Aug 2000 13:23:18 +0000 (13:23 +0000)
tests/cp/perm

index b87c8fa5aecb574273f6c11f0ade5a119474a740..4bc3cddbcd0146ebef61d5370a0a51b6f52ab104 100755 (executable)
@@ -1,6 +1,14 @@
 #!/bin/sh
 # Make sure the permission-preserving code in copy.c (mv, cp, install) works.
 
+if test "$VERBOSE" = yes; then
+  set -x
+  cp --version
+  mv --version
+fi
+
+. $srcdir/../envvar-check
+
 pwd=`pwd`
 tmp=perm.$$
 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
@@ -10,8 +18,7 @@ framework_failure=0
 mkdir $tmp || framework_failure=1
 cd $tmp || framework_failure=1
 
-touch f || framework_failure=1
-chmod u=r,go= f || framework_failure=1
+umask 037
 
 if test $framework_failure = 1; then
   echo 'failure in testing framework'
@@ -20,25 +27,39 @@ fi
 
 fail=0
 
-cp -p f f2 || fail=1
-
-# Permissions on f2 must be `-r--------'
-
-set X `ls -l f2`
-shift
-test "$1" = -r-------- || fail=1
-chmod u+w,g=rwx f2 || fail=1
-
-# Again, but with an existing target.
-cp -p f f2 || fail=1
-set X `ls -l f2`
-shift
-test "$1" = -r-------- || fail=1
-
-# Again, but with an existing target, and this time with `-f'.
-cp -p -f f f2 || fail=1
-set X `ls -l f2`
-shift
-test "$1" = -r-------- || fail=1
+# Now, try it with `mv', with combinations of --force, no-f and
+# existing-destination and not.
+for cmd in mv 'cp -p' cp; do
+  for force in '' -f; do
+    for existing_dest in yes no; do
+      for g_perm in r w x rw wx xr rwx; do
+       for o_perm in r w x rw wx xr rwx; do
+         touch src || exit 1
+         chmod u=r,go= src || exit 1
+         rm -f dest
+         test $existing_dest = yes && {
+           touch dest || exit 1
+           chmod u=rw,g=$g_perm,o=$o_perm dest || exit 1
+           }
+         $cmd $force src dest || exit 1
+         test "$cmd" = mv && test -f src && exit 1
+         test "$cmd" = cp && { test -f src || exit 1; }
+         set X `ls -l dest`
+         shift
+         case "$cmd:$force:$existing_dest" in
+           cp::yes)
+             _g_perm=`echo rwx|sed 's/[^'$g_perm']/-/g'`
+             _o_perm=`echo rwx|sed 's/[^'$o_perm']/-/g'`
+             expected_perms=-rw-$_g_perm$_o_perm;;
+           *) expected_perms=-r--------;;
+         esac
+         test x$1 = x$expected_perms || exit 1
+         # Perform only one iteration when there's no existing destination.
+         test $existing_dest = no && break 3
+       done
+      done
+    done
+  done
+done
 
 (exit $fail); exit