cp: with --no-preserve=mode ensure set-group-ID bits maintained on dirs
[coreutils.git] / tests / mv / update.sh
blob16435780369bcfbc3a232ff25d28202c83ef1a63
1 #!/bin/sh
2 # make sure --update works as advertised
4 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
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.
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.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ cp mv
22 test_reset() {
23 echo old > old || framework_failure_
24 touch -d yesterday old || framework_failure_
25 echo new > new || framework_failure_
28 test_reset
29 for interactive in '' -i; do
30 for cp_or_mv in cp mv; do
31 # This is a no-op, with no prompt.
32 # With coreutils-6.9 and earlier, using --update with -i would
33 # mistakenly elicit a prompt.
34 $cp_or_mv $interactive --update old new < /dev/null > out 2>&1 || fail=1
35 compare /dev/null out || fail=1
36 case "$(cat new)" in new) ;; *) fail=1 ;; esac
37 case "$(cat old)" in old) ;; *) fail=1 ;; esac
38 done
39 done
41 # These should perform the rename / copy
42 for update_option in '--update' '--update=older' '--update=all' \
43 '--update=none --update=all'; do
44 test_reset
45 mv $update_option new old || fail=1
46 test -f new && fail=1
47 case "$(cat old)" in new) ;; *) fail=1 ;; esac
49 test_reset
50 cp $update_option new old || fail=1
51 case "$(cat old)" in new) ;; *) fail=1 ;; esac
52 case "$(cat new)" in new) ;; *) fail=1 ;; esac
53 done
55 # These should not perform the rename / copy
56 for update_option in '--update=none' '--update=none-fail' \
57 '--update=all --update=none' \
58 '--update=all --no-clobber' \
59 '--no-clobber --update=all'; do
61 echo "$update_option" | grep 'fail' >/dev/null && ret=1 || ret=0
63 test_reset
64 returns_ $ret mv $update_option new old || fail=1
65 case "$(cat new)" in new) ;; *) fail=1 ;; esac
66 case "$(cat old)" in old) ;; *) fail=1 ;; esac
68 test_reset
69 returns_ $ret cp $update_option new old || fail=1
70 case "$(cat new)" in new) ;; *) fail=1 ;; esac
71 case "$(cat old)" in old) ;; *) fail=1 ;; esac
72 done
74 Exit $fail