Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / mv / trailing-slash
1 #!/bin/sh
2 # On some operating systems, e.g. SunOS-4.1.1_U1 on sun3x,
3 # rename() doesn't accept trailing slashes.
4 # Also, ensure that "mv dir non-exist-dir/" works.
5 # Also, ensure that "cp dir non-exist-dir/" works.
6
7 # Copyright (C) 2004, 2006 Free Software Foundation, Inc.
8
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
13
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 # GNU General Public License for more details.
18
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 # 02110-1301, USA.
23
24 if test "$VERBOSE" = yes; then
25   set -x
26   mv --version
27 fi
28
29 pwd=`pwd`
30 tmp=mv-tslash.$$
31 trap 'status=$?; cd "$pwd" && exec 1>&2; rm -rf $tmp && exit $status' 0
32 trap '(exit $?); exit' 1 2 13 15
33
34 . $srcdir/../envvar-check
35
36 framework_failure=0
37 mkdir $tmp || framework_failure=1
38 cd $tmp || framework_failure=1
39 mkdir foo || framework_failure=1
40
41 if test $framework_failure = 1; then
42   echo 'failure in testing framework' 1>&2
43   exit 1
44 fi
45
46 fail=0
47
48 mv foo/ bar || fail=1
49
50 # mv and cp would misbehave for coreutils versions [5.3.0..5.97], 6.0 and 6.1
51 for cmd in mv 'cp -r'; do
52   for opt in '' -T -u; do
53     rm -rf d e || framework_failure=1
54     mkdir d    || framework_failure=1
55     if test $framework_failure = 1; then
56       echo 'failure in testing framework'
57       (exit 1); exit 1
58     fi
59
60     $cmd $opt d e/ || fail=1
61     if test "$cmd" = mv; then
62       test -d d && fail=1
63     else
64       test -d d || fail=1
65     fi
66     test -d e || fail=1
67   done
68 done
69
70 # We would like the erroneous-looking "mv any non-dir/" to fail,
71 # but with the current implementation, it depends on how the
72 # underlying rename syscall handles the trailing slash.
73 # It does fail, as desired, on recent Linux and Solaris systems.
74 #touch a a2
75 #mv a a2/ && fail=1
76
77 (exit $fail); exit $fail