1#!/bin/sh
2# move a file onto itself
3
4# Copyright (C) 1999-2023 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 <https://www.gnu.org/licenses/>.
18
19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ mv
21
22ff=mvforce
23ff2=mvforce2
24
25echo force-contents > $ff || framework_failure_
26ln $ff $ff2 || framework_failure_
27
28# mv should fail for the same name, or separate hardlinks as in
29# both cases rename() will do nothing and return success.
30# One could unlink(src) in the hardlink case, but that would
31# introduce races with overlapping mv instances removing both hardlinks.
32
33for dest in $ff $ff2; do
34  # This mv command should exit nonzero.
35  mv $ff $dest > out 2>&1 && fail=1
36
37  printf "mv: '$ff' and '$dest' are the same file\n" > exp
38  compare exp out || fail=1
39
40  test $(cat $ff) = force-contents || fail=1
41done
42
43Exit $fail
44