* Noteworthy changes in release ?.? (????-??-??) [?]
+** Bug fixes
+
+ mv now lets you move a symlink onto a same-inode destination file that
+ has two or more hard links. Before, it would reject that, saying that
+ they are the same, implicitly warning you that the move would result in
+ data loss. In this unusual case, when not moving the symlink onto its
+ referent, there is no risk of data loss, since the symlink will
+ typically still point to one of the hard links.
+
* Noteworthy changes in release 8.15 (2012-01-06) [stable]
Alfred M. Szmidt ams@kemisten.nu
Ambrose Feinstein ambrose@google.com
Amr Ali amr.ali.cc@gmail.com
+Anders Kaseorg andersk@mit.edu
Andi Kleen freitag@alancoxonachip.com
Andre Novaes Cunha Andre.Cunha@br.global-one.net
Andreas Frische andreasfrische@gmail.com
Matej Vela mvela@public.srce.hr
Matias A. Fonzo selk@dragora.org
Matt Kraai kraai@ftbfs.org
+Matt McCutchen matt@mattmccutchen.net
Matt Perry matt@primefactor.com
Matt Pham mattvpham@gmail.com
Matt Schalit mschalit@pacbell.net
#include "acl.h"
#include "backupfile.h"
#include "buffer-lcm.h"
+#include "canonicalize.h"
#include "copy.h"
#include "cp-hash.h"
#include "extent-scan.h"
}
}
+ /* At this point, it is normally an error (data loss) to move a symlink
+ onto its referent, but in at least one narrow case, it is not:
+ In move mode, when
+ 1) src is a symlink,
+ 2) dest has a link count of 2 or more and
+ 3) dest and the referent of src are not the same directory entry,
+ then it's ok, since while we'll lose one of those hard links,
+ src will still point to a remaining link.
+ Note that technically, condition #3 obviates condition #2, but we
+ retain the 1 < st_nlink condition because that means fewer invocations
+ of the more expensive #3.
+
+ Given this,
+ $ touch f && ln f l && ln -s f s
+ $ ls -og f l s
+ -rw-------. 2 0 Jan 4 22:46 f
+ -rw-------. 2 0 Jan 4 22:46 l
+ lrwxrwxrwx. 1 1 Jan 4 22:46 s -> f
+ this must fail: mv s f
+ this must succeed: mv s l */
+ if (x->move_mode
+ && S_ISLNK (src_sb->st_mode)
+ && 1 < dst_sb_link->st_nlink)
+ {
+ char *abs_src = canonicalize_file_name (src_name);
+ if (abs_src)
+ {
+ bool result = ! same_name (abs_src, dst_name);
+ free (abs_src);
+ return result;
+ }
+ }
+
/* It's ok to remove a destination symlink. But that works only when we
unlink before opening the destination and when the source and destination
files are on the same partition. */
to use fts, so using alloca here will be less of a problem. */
ASSIGN_STRDUPA (dst_backup, tmp_backup);
free (tmp_backup);
+ /* In move mode, when src_name and dst_name are on the
+ same partition (FIXME, and when they are non-directories),
+ make the operation atomic: link dest
+ to backup, then rename src to dest. */
if (rename (dst_name, dst_backup) != 0)
{
if (errno != ENOENT)
mv/part-symlink \
mv/partition-perm \
mv/perm-1 \
+ mv/symlink-onto-hardlink \
mv/to-symlink \
mv/trailing-slash \
mv/update \
--- /dev/null
+#!/bin/sh
+# Ensure that mv works with a few symlink-onto-hard-link cases.
+
+# Copyright (C) 2012 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/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+print_ver_ mv
+
+touch f || framework_failure_
+ln f h || framework_failure_
+ln -s f s || framework_failure_
+
+# Given two links f and h to some important content, and a symlink s to f,
+# "mv s f" must fail because it might then be hard to find the link, h.
+# "mv s l" may succeed because then, s (now "l") still points to f.
+# Of course, if the symlink were being moved into a different destination
+# directory, things would be very different, and, I suspect, implausible.
+
+echo "mv: 's' and 'f' are the same file" > exp || framework_failure_
+mv s f > out 2> err && fail=1
+compare /dev/null out || fail=1
+compare exp err || fail=1
+
+mv s l > out 2> err || fail=1
+compare /dev/null out || fail=1
+compare /dev/null err || fail=1
+
+Exit $fail