mv: never unlink a destination file before calling rename
This commit is contained in:
parent
f0d582d4d6
commit
5568ef100c
103
coreutils-mvatomic.patch
Normal file
103
coreutils-mvatomic.patch
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
src/copy.c | 5 +++--
|
||||||
|
tests/mv/Makefile.am | 4 ++--
|
||||||
|
tests/mv/atomic2 | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||||
|
3 files changed, 55 insertions(+), 4 deletions(-)
|
||||||
|
create mode 100755 tests/mv/atomic2
|
||||||
|
|
||||||
|
diff --git a/src/copy.c b/src/copy.c
|
||||||
|
index fd31b5c..208a674 100644
|
||||||
|
--- a/src/copy.c
|
||||||
|
+++ b/src/copy.c
|
||||||
|
@@ -1339,10 +1339,11 @@ copy_internal (char const *src_name, char const *dst_name,
|
||||||
|
new_dst = true;
|
||||||
|
}
|
||||||
|
else if (! S_ISDIR (dst_sb.st_mode)
|
||||||
|
+ /* Never unlink dst_name when in move mode. */
|
||||||
|
+ && ! x->move_mode
|
||||||
|
&& (x->unlink_dest_before_opening
|
||||||
|
|| (x->preserve_links && 1 < dst_sb.st_nlink)
|
||||||
|
- || (!x->move_mode
|
||||||
|
- && x->dereference == DEREF_NEVER
|
||||||
|
+ || (x->dereference == DEREF_NEVER
|
||||||
|
&& S_ISLNK (src_sb.st_mode))
|
||||||
|
))
|
||||||
|
{
|
||||||
|
diff --git a/tests/mv/Makefile.am b/tests/mv/Makefile.am
|
||||||
|
index c121911..92ec68e 100644
|
||||||
|
--- a/tests/mv/Makefile.am
|
||||||
|
+++ b/tests/mv/Makefile.am
|
||||||
|
@@ -1,7 +1,6 @@
|
||||||
|
# Make coreutils tests for "mv". -*-Makefile-*-
|
||||||
|
|
||||||
|
-# Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
|
||||||
|
-# Free Software Foundation, Inc.
|
||||||
|
+# Copyright (C) 1998-2008 Free Software Foundation, Inc.
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@@ -17,6 +16,7 @@
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
TESTS = \
|
||||||
|
+ atomic2 \
|
||||||
|
sticky-to-xpart \
|
||||||
|
hard-verbose \
|
||||||
|
backup-dir \
|
||||||
|
diff --git a/tests/mv/atomic2 b/tests/mv/atomic2
|
||||||
|
new file mode 100755
|
||||||
|
index 0000000..d1029aa
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/tests/mv/atomic2
|
||||||
|
@@ -0,0 +1,50 @@
|
||||||
|
+#!/bin/sh
|
||||||
|
+# ensure that mv doesn't first unlink a multi-hard-linked destination
|
||||||
|
+
|
||||||
|
+# Copyright (C) 2008 Free Software Foundation, Inc.
|
||||||
|
+
|
||||||
|
+# This program is free software: you can redistribute it and/or modify
|
||||||
|
+# it under the terms of the GNU General Public License as published by
|
||||||
|
+# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
+# (at your option) any later version.
|
||||||
|
+
|
||||||
|
+# This program is distributed in the hope that it will be useful,
|
||||||
|
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
+# GNU General Public License for more details.
|
||||||
|
+
|
||||||
|
+# You should have received a copy of the GNU General Public License
|
||||||
|
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
+
|
||||||
|
+if test "$VERBOSE" = yes; then
|
||||||
|
+ set -x
|
||||||
|
+ mv --version
|
||||||
|
+fi
|
||||||
|
+
|
||||||
|
+. $srcdir/../test-lib.sh
|
||||||
|
+require_strace_
|
||||||
|
+
|
||||||
|
+# Before the fix, mv would unnecessarily unlink the destination symlink:
|
||||||
|
+# $ rm -f a b b2; touch a b; ln b b2; strace -e unlink /p/bin/mv a b
|
||||||
|
+# unlink("b") = 0
|
||||||
|
+#
|
||||||
|
+# With the fix, it doesn't call unlink:
|
||||||
|
+# $ rm -f a b b2; touch a b; ln b b2; strace -e unlink ./mv a b
|
||||||
|
+# $
|
||||||
|
+
|
||||||
|
+touch a b || framework_failure
|
||||||
|
+ln b b2 || framework_failure
|
||||||
|
+
|
||||||
|
+fail=0
|
||||||
|
+
|
||||||
|
+strace -qe unlink mv a b > out 2>&1 || fail=1
|
||||||
|
+$EGREP 'unlink.*"b"' out && fail=1
|
||||||
|
+
|
||||||
|
+# Ensure that the source, "a", is gone.
|
||||||
|
+ls -dl a > /dev/null 2>&1 && fail=1
|
||||||
|
+
|
||||||
|
+# Ensure that the destination, "b", has link count 1.
|
||||||
|
+n_links=`stat --printf=%h b` || fail=1
|
||||||
|
+test "$n_links" = 1 || fail=1
|
||||||
|
+
|
||||||
|
+(exit $fail); exit $fail
|
||||||
|
--
|
||||||
|
1.5.5.rc0.7.g57e83
|
@ -1,7 +1,7 @@
|
|||||||
Summary: The GNU core utilities: a set of tools commonly used in shell scripts
|
Summary: The GNU core utilities: a set of tools commonly used in shell scripts
|
||||||
Name: coreutils
|
Name: coreutils
|
||||||
Version: 6.10
|
Version: 6.10
|
||||||
Release: 13%{?dist}
|
Release: 14%{?dist}
|
||||||
License: GPLv3+
|
License: GPLv3+
|
||||||
Group: System Environment/Base
|
Group: System Environment/Base
|
||||||
Url: http://www.gnu.org/software/coreutils/
|
Url: http://www.gnu.org/software/coreutils/
|
||||||
@ -20,6 +20,7 @@ Source203: coreutils-runuser-l.pamd
|
|||||||
# From upstream
|
# From upstream
|
||||||
Patch1: coreutils-6.10-verbose.patch
|
Patch1: coreutils-6.10-verbose.patch
|
||||||
Patch2: coreutils-dddoubleclose.patch
|
Patch2: coreutils-dddoubleclose.patch
|
||||||
|
Patch3: coreutils-mvatomic.patch
|
||||||
|
|
||||||
# Our patches
|
# Our patches
|
||||||
Patch100: coreutils-chgrp.patch
|
Patch100: coreutils-chgrp.patch
|
||||||
@ -99,6 +100,7 @@ cd %name-%version
|
|||||||
# From upstream
|
# From upstream
|
||||||
%patch1 -p1 -b .verbose
|
%patch1 -p1 -b .verbose
|
||||||
%patch2 -p1 -b .doubleclose
|
%patch2 -p1 -b .doubleclose
|
||||||
|
%patch3 -p1 -b .atomic
|
||||||
|
|
||||||
# Our patches
|
# Our patches
|
||||||
%patch100 -p1 -b .chgrp
|
%patch100 -p1 -b .chgrp
|
||||||
@ -295,6 +297,10 @@ fi
|
|||||||
/sbin/runuser
|
/sbin/runuser
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Mar 19 2008 Ondrej Vasik <ovasik@redhat.com> - 6.10-14
|
||||||
|
- mv: never unlink a destination file before calling rename
|
||||||
|
(upstream, #438076)
|
||||||
|
|
||||||
* Mon Mar 17 2008 Ondrej Vasik <ovasik@redhat.com> - 6.10-13
|
* Mon Mar 17 2008 Ondrej Vasik <ovasik@redhat.com> - 6.10-13
|
||||||
- disable echo option separator behavior(added by #431005,
|
- disable echo option separator behavior(added by #431005,
|
||||||
request for removal #437653 + upstream)
|
request for removal #437653 + upstream)
|
||||||
|
Loading…
Reference in New Issue
Block a user