GNU bug report logs -
#31364
cp -rfs: Fails to overwrite a symlink when it is on a different device
Previous Next
Reported by: Illia Bobyr <ibobyr <at> google.com>
Date: Fri, 4 May 2018 23:48:02 UTC
Severity: normal
Done: Pádraig Brady <P <at> draigBrady.com>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your bug report
#31364: cp -rfs: Fails to overwrite a symlink when it is on a different device
which was filed against the coreutils package, has been closed.
The explanation is attached below, along with your original report.
If you require more details, please reply to 31364 <at> debbugs.gnu.org.
--
31364: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=31364
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
Pushed at https://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commitdiff;h=v8.29-36-gd3daa95
marking this as done
cheers,
Pádraig.
[Message part 3 (message/rfc822, inline)]
[Message part 4 (text/plain, inline)]
Hello,
I have found a bug in "cp -rfs".
Steps to reproduce:
1. Given "path1" and "path2" are on different devices.
2. $ touch "path1/file"
3. $ cd path2/; ln -s path1/file
4. $ cp --symbolic-link --force --recursive path1/file .
Expected:
The link is overwritten with an exact copy.
Actual result:
cp shows an error:
cp: 'path1/file' and './file' are the same file
This bug was introduced in
http://git.savannah.gnu.org/cgit/coreutils.git/commit/?id=376967889ed7ed561e46ff6d88a66779db62737a
Specifically this hunk:
diff --git a/src/copy.c b/src/copy.c
index e3832c2..9dbd536 100644
--- a/src/copy.c
<http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/copy.c?id=2f69dba5df8caaf9eda658c1808b1379e9949f22>
+++ b/src/copy.c
<http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/copy.c?id=376967889ed7ed561e46ff6d88a66779db62737a>
@@ -46,6 +46,7 @@
#include "file-set.h"
#include "filemode.h"
#include "filenamecat.h"
+#include "force-link.h"
#include "full-write.h"
#include "hash.h"
#include "hash-triple.h"
@@ -1623,11 +1624,13 @@ same_file_ok (char const *src_name, struct stat
const *src_sb,
}
}
- /* 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. */
- if (x->unlink_dest_before_opening
- && S_ISLNK (dst_sb_link->st_mode))
+ /* It's ok to remove a destination symlink. But that works only
+ when creating symbolic links, or when the source and destination
+ are on the same file system and when creating hard links or when
+ unlinking before opening the destination. */
+ if (x->symbolic_link
+ || ((x->hard_link || x->unlink_dest_before_opening)
+ && S_ISLNK (dst_sb_link->st_mode)))
return dst_sb_link->st_dev == src_sb_link->st_dev;
if (x->dereference == DEREF_NEVER)
Two patches that fix the issue are attached.
They are against the current master in
https://github.com/coreutils/coreutils
The changes are also here:
https://github.com/coreutils/coreutils/compare/master...ilya-bobyr:master
Thank you, Illia Bobyr
[Message part 5 (text/html, inline)]
[0002-cp-Overwrite-symlinks-on-another-device.patch (text/x-patch, attachment)]
[0001-cp-No-dup-check-for-unlink_dest_after_failed_open.patch (text/x-patch, attachment)]
This bug report was last modified 7 years and 11 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.