Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 627812

Summary: sys-apps/coreutils mv behavior with hard links to same file
Product: Gentoo Linux Reporter: Xuefer <xuefer>
Component: Current packagesAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED INVALID    
Severity: normal CC: floppym
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Xuefer 2017-08-14 04:14:38 UTC
$ rm -f a b
$ touch a
$ ln a b
$ mv a b
mv: 'a' and 'b' are the same file

expected: mv is expected to overwrite b using a, which mean in this case, unlink a, rename a to b
Comment 1 Mike Gilbert gentoo-dev 2017-08-14 04:44:07 UTC
POSIX says this behavior is correct.

http://pubs.opengroup.org/onlinepubs/9699919799/utilities/mv.html

"The specification ensures that mv a a will not alter the contents of file a, and allows the implementation to issue an error that a file cannot be moved onto itself. Likewise, when a and b are hard links to the same file, mv a b will not alter b, but if a diagnostic is not issued, then it is unspecified whether a is left untouched (as it would be by the rename() function) or unlinked (reducing the link count of b)."