install: add --compare (-C) option to install file only when necessary
[platform/upstream/coreutils.git] / tests / install / install-C
1 #!/bin/sh
2 # Ensure "install -C" works. (basic tests)
3
4 # Copyright (C) 2008 Free Software Foundation, Inc.
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19 if test "$VERBOSE" = yes; then
20   set -x
21   ginstall --version
22 fi
23
24 . $srcdir/test-lib.sh
25
26 mode1=0644
27 mode2=0755
28 mode3=1755
29
30 fail=0
31
32 echo test > a || framework_failure
33 echo "\`a' -> \`b'" > out_installed_first
34 echo "removed \`b'
35 \`a' -> \`b'" > out_installed_second
36 > out_empty
37
38 # destination file does not exist
39 ginstall -Cv -m$mode1 a b > out || fail=1
40 compare out out_installed_first || fail=1
41
42 # destination file exists
43 ginstall -Cv -m$mode1 a b > out || fail=1
44 compare out out_empty || fail=1
45
46 # destination file exists (long option)
47 ginstall -v --compare -m$mode1 a b > out || fail=1
48 compare out out_empty || fail=1
49
50 # destination file exists but -C is not given
51 ginstall -v -m$mode1 a b > out || fail=1
52 compare out out_installed_second || fail=1
53
54 # option -C ignored if any non-permission mode should be set
55 ginstall -Cv -m$mode3 a b > out || fail=1
56 compare out out_installed_second || fail=1
57 ginstall -Cv -m$mode3 a b > out || fail=1
58 compare out out_installed_second || fail=1
59
60 # files are not regular files
61 ln -s a c || framework_failure
62 ln -s b d || framework_failure
63 ginstall -Cv -m$mode1 c d > out || fail=1
64 echo "removed \`d'
65 \`c' -> \`d'" > out_installed_second_cd
66 compare out out_installed_second_cd || fail=1
67
68 # destination file exists but content differs
69 echo test1 > a || framework_failure
70 ginstall -Cv -m$mode1 a b > out || fail=1
71 compare out out_installed_second || fail=1
72 ginstall -Cv -m$mode1 a b > out || fail=1
73 compare out out_empty || fail=1
74
75 # destination file exists but content differs (same size)
76 echo test2 > a || framework_failure
77 ginstall -Cv -m$mode1 a b > out || fail=1
78 compare out out_installed_second || fail=1
79 ginstall -Cv -m$mode1 a b > out || fail=1
80 compare out out_empty || fail=1
81
82 # destination file exists but mode differs
83 ginstall -Cv -m$mode2 a b > out || fail=1
84 compare out out_installed_second || fail=1
85 ginstall -Cv -m$mode2 a b > out || fail=1
86 compare out out_empty || fail=1
87
88 # options -C and --preserve-timestamps are mutually exclusive
89 ginstall -C --preserve-timestamps a b && fail=1
90
91 # options -C and --strip are mutually exclusive
92 ginstall -C --strip --strip-program=echo a b && fail=1
93
94 Exit $fail