From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 26 13:44:05 2019 Received: (at submit) by debbugs.gnu.org; 26 Jul 2019 17:44:05 +0000 Received: from localhost ([127.0.0.1]:43321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hr4GC-0000zh-RA for submit@debbugs.gnu.org; Fri, 26 Jul 2019 13:44:05 -0400 Received: from lists.gnu.org ([209.51.188.17]:51599) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hr4GA-0000zZ-KX for submit@debbugs.gnu.org; Fri, 26 Jul 2019 13:44:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48258) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hr4G9-0008Lt-Ff for bug-coreutils@gnu.org; Fri, 26 Jul 2019 13:44:02 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hr4G8-0006vn-Ao for bug-coreutils@gnu.org; Fri, 26 Jul 2019 13:44:01 -0400 Received: from mail.gentoo.org ([2001:470:ea4a:1:5054:ff:fec7:86e4]:41071 helo=smtp.gentoo.org) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hr4G8-0006ke-4A for bug-coreutils@gnu.org; Fri, 26 Jul 2019 13:44:00 -0400 Received: from sf (trofi-1-pt.tunnel.tserv1.lon2.ipv6.he.net [IPv6:2001:470:1f1c:a0f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: slyfox) by smtp.gentoo.org (Postfix) with ESMTPSA id 9CDDD348B81 for ; Fri, 26 Jul 2019 17:43:55 +0000 (UTC) Date: Fri, 26 Jul 2019 18:43:51 +0100 From: Sergei Trofimovich To: bug-coreutils@gnu.org Subject: mv fails to clobber target if it's a hardlink of a source Message-ID: <20190726184351.50ecfee9@sf> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:470:ea4a:1:5054:ff:fec7:86e4 X-Spam-Score: -1.6 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.6 (--) The below is a bug initially reported by Xuefer at https://bugs.gentoo.org/646412. Reproducer: $ mv --version mv (GNU coreutils) 8.31 Packaged by Gentoo (8.31 (p0)) $ touch a.aa $ ln a.aa b.bb $ mv a.aa b.bb mv: 'a.aa' and 'b.bb' are the same file For comparison if fines are unrelated 'mv' just works: $ touch a.aa $ touch b.bb $ mv a.aa b.bb $ echo $? 0 Fun fact: busybox does not complain about hardlinked files: $ touch a.aa $ ln a.aa b.bb $ busybox mv a.aa b.bb $ echo $? $ echo $? 0 Some context on where these accidentally hardlinked files come from: gdb build system simplistically does the following: $ gcc a.c -o a.tmp.o && mv a.tmp.o a.o ccache has a mode to create a resulting file by hardlinking if possible instead of copying data round. If the above command is ran without ccache wrapper 'a.tmp.o' is always a new file. Otherwise if it's ran via ccache with CCACHE_HARDLINK=1 then 'a.tmp.o' and 'a.o' and both hardlinks of a file stored in cache originally. Is it an 'mv's bug or a feature to prevent hardlinked file clobbering? If feels like an unnecessary restriction. Thank you! -- Sergei From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 26 14:01:54 2019 Received: (at 36818) by debbugs.gnu.org; 26 Jul 2019 18:01:54 +0000 Received: from localhost ([127.0.0.1]:43335 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hr4XS-0001R2-7K for submit@debbugs.gnu.org; Fri, 26 Jul 2019 14:01:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40474) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hr4XP-0001Qm-8y for 36818@debbugs.gnu.org; Fri, 26 Jul 2019 14:01:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C037885543; Fri, 26 Jul 2019 18:01:45 +0000 (UTC) Received: from [10.3.116.93] (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4A9666012D; Fri, 26 Jul 2019 18:01:45 +0000 (UTC) Subject: Re: bug#36818: mv fails to clobber target if it's a hardlink of a source To: Sergei Trofimovich , 36818@debbugs.gnu.org References: <20190726184351.50ecfee9@sf> From: Eric Blake Openpgp: preference=signencrypt Autocrypt: addr=eblake@redhat.com; keydata= xsBNBEvHyWwBCACw7DwsQIh0kAbUXyqhfiKAKOTVu6OiMGffw2w90Ggrp4bdVKmCaEXlrVLU xphBM8mb+wsFkU+pq9YR621WXo9REYVIl0FxKeQo9dyQBZ/XvmUMka4NOmHtFg74nvkpJFCD TUNzmqfcjdKhfFV0d7P/ixKQeZr2WP1xMcjmAQY5YvQ2lUoHP43m8TtpB1LkjyYBCodd+LkV GmCx2Bop1LSblbvbrOm2bKpZdBPjncRNob73eTpIXEutvEaHH72LzpzksfcKM+M18cyRH+nP sAd98xIbVjm3Jm4k4d5oQyE2HwOur+trk2EcxTgdp17QapuWPwMfhaNq3runaX7x34zhABEB AAHNHkVyaWMgQmxha2UgPGVibGFrZUByZWRoYXQu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qlj/z6Ugk027/3GUjHHr8WkeL1ezWepYDY7WSoXwfoAL 2UXYsMAr/uUncSKlfjvArhsej0S4zbqim2ZY6S8aRWw94J3bSvJR+Nwbs34GPTD4Pg== Organization: Red Hat, Inc. Message-ID: <8b87300c-2abb-0d43-b2bd-2a15e5bbf058@redhat.com> Date: Fri, 26 Jul 2019 13:01:44 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190726184351.50ecfee9@sf> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="7VWBntGGvrAswUVioDK3oSiHjJsXLtksq" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 26 Jul 2019 18:01:45 +0000 (UTC) X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 36818 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --7VWBntGGvrAswUVioDK3oSiHjJsXLtksq Content-Type: multipart/mixed; boundary="XthkjqrRjDhM8CgIRLEXbLtBJoE1nWXTn"; protected-headers="v1" From: Eric Blake To: Sergei Trofimovich , 36818@debbugs.gnu.org Message-ID: <8b87300c-2abb-0d43-b2bd-2a15e5bbf058@redhat.com> Subject: Re: bug#36818: mv fails to clobber target if it's a hardlink of a source References: <20190726184351.50ecfee9@sf> In-Reply-To: <20190726184351.50ecfee9@sf> --XthkjqrRjDhM8CgIRLEXbLtBJoE1nWXTn Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable On 7/26/19 12:43 PM, Sergei Trofimovich wrote: > Is it an 'mv's bug or a feature to prevent hardlinked file clobbering? > If feels like an unnecessary restriction. It's a POSIX (mis-)feature that for hard links, rename("file1", "file2") is a mandatory no-op (no error, but also no change to the existence or contents of either file1 or file2). Back under POSIX 2001, mv was required to behave identically to the rename() syscall. But this was confusing enough that POSIX 2008 relaxed the wording as follows, inspired in part by complaint from GNU coreutils: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/mv.html "If the source_file operand and destination path resolve to either the same existing directory entry or different directory entries for the same existing file, then the destination path shall not be removed, and one of the following shall occur: No change is made to source_file, no error occurs, and no diagnostic is issued. No change is made to source_file, a diagnostic is issued to standard error identifying the two names, and the exit status is affected. If the source_file operand and destination path name distinct directory entries, then the source_file operand is removed, no error occurs, and no diagnostic is issued." The difference between GNU coreutils and busybox both appear to be compliant behaviors (you didn't actually show after the 'mv' command whether a.aa still exists, so I can't tell whether busybox implemented option 1 or option 3; but it appears GNU implemented option 2). Option 1 is probably the least intuitive but is the historical behavior when you use rename() without any checking. Option 2 at least points out the issue that your usage is not going to be universally portable. Option 3 is closest to what happens when there are no hard links. --=20 Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org --XthkjqrRjDhM8CgIRLEXbLtBJoE1nWXTn-- --7VWBntGGvrAswUVioDK3oSiHjJsXLtksq Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAEBCAAdFiEEccLMIrHEYCkn0vOqp6FrSiUnQ2oFAl07QAgACgkQp6FrSiUn Q2pL+ggArfJU4HzOifdlDhGvlLBirgjImvAhiLfD4fmgs8TYW3b7aWEs7q9ZoNm9 hMH2kLlgWSnt6EWPwyk+GftRif9dU9QHfDpqwDEc+33GXy7wtL7xKmej/mnaBQuY OKy4dhOnUjXA983lQ7dlRA4aBmrEB6Xkd+W+7bc3tWIJRhqZHlQDy6d8uS6lt3lm WeHLG+zgihYebq+SRnIr39q4D69KwY3ZrglQ2bpZOdcCc1NgW86Jf34pzEyqnhMZ ncM9YPuIs5bjwCPvRifg2Re+s3ELGgOtHt4UY6EGsfjLTP9SaydT0SAxPEeJig2I sCGs+A+8bvrLFUjP06NRfSHylB13dA== =FWNK -----END PGP SIGNATURE----- --7VWBntGGvrAswUVioDK3oSiHjJsXLtksq-- From debbugs-submit-bounces@debbugs.gnu.org Fri Jul 26 14:23:37 2019 Received: (at 36818) by debbugs.gnu.org; 26 Jul 2019 18:23:37 +0000 Received: from localhost ([127.0.0.1]:43350 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hr4sT-0001xk-83 for submit@debbugs.gnu.org; Fri, 26 Jul 2019 14:23:37 -0400 Received: from smtp.gentoo.org ([140.211.166.183]:42428) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hr4sQ-0001xR-Nx; Fri, 26 Jul 2019 14:23:35 -0400 Received: from sf (trofi-1-pt.tunnel.tserv1.lon2.ipv6.he.net [IPv6:2001:470:1f1c:a0f::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: slyfox) by smtp.gentoo.org (Postfix) with ESMTPSA id B429B348C37; Fri, 26 Jul 2019 18:23:27 +0000 (UTC) Date: Fri, 26 Jul 2019 19:23:22 +0100 From: Sergei Trofimovich To: Eric Blake , 36818-done@debbugs.gnu.org Subject: Re: bug#36818: mv fails to clobber target if it's a hardlink of a source Message-ID: <20190726192322.58a437d8@sf> In-Reply-To: <8b87300c-2abb-0d43-b2bd-2a15e5bbf058@redhat.com> References: <20190726184351.50ecfee9@sf> <8b87300c-2abb-0d43-b2bd-2a15e5bbf058@redhat.com> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/Ti_i.wWF.BQk=eObnfk+q5+"; protocol="application/pgp-signature" X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 36818 Cc: 36818@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) --Sig_/Ti_i.wWF.BQk=eObnfk+q5+ Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Fri, 26 Jul 2019 13:01:44 -0500 Eric Blake wrote: > On 7/26/19 12:43 PM, Sergei Trofimovich wrote: >=20 > > Is it an 'mv's bug or a feature to prevent hardlinked file clobbering? > > If feels like an unnecessary restriction. =20 >=20 > It's a POSIX (mis-)feature that for hard links, rename("file1", "file2") > is a mandatory no-op (no error, but also no change to the existence or > contents of either file1 or file2). Back under POSIX 2001, mv was > required to behave identically to the rename() syscall. But this was > confusing enough that POSIX 2008 relaxed the wording as follows, > inspired in part by complaint from GNU coreutils: >=20 > https://pubs.opengroup.org/onlinepubs/9699919799/utilities/mv.html >=20 > "If the source_file operand and destination path resolve to either the > same existing directory entry or different directory entries for the > same existing file, then the destination path shall not be removed, and > one of the following shall occur: >=20 > No change is made to source_file, no error occurs, and no diagnostic > is issued. >=20 > No change is made to source_file, a diagnostic is issued to standard > error identifying the two names, and the exit status is affected. >=20 > If the source_file operand and destination path name distinct > directory entries, then the source_file operand is removed, no error > occurs, and no diagnostic is issued." >=20 > The difference between GNU coreutils and busybox both appear to be > compliant behaviors (you didn't actually show after the 'mv' command > whether a.aa still exists, so I can't tell whether busybox implemented > option 1 or option 3; Oh, I did not realize source file did not disappear. Looks like busybox's behaviour is an 'option 1': $ ls -i a.aa b.bb 208636260 a.aa 208636260 b.bb $ strace -f busybox mv a.aa b.bb ... stat("b.bb", {st_mode=3DS_IFREG|0644, st_size=3D0, ...}) =3D 0 access("b.bb", W_OK) =3D 0 rename("a.aa", "b.bb") =3D 0 exit_group(0) =3D ? +++ exited with 0 +++ $ ls -i a.aa b.bb 208636260 a.aa 208636260 b.bb > but it appears GNU implemented option 2). Option > 1 is probably the least intuitive but is the historical behavior when > you use rename() without any checking. Option 2 at least points out the > issue that your usage is not going to be universally portable. Option 3 > is closest to what happens when there are no hard links. Thank you for the quick response. The bug can be closed as WAI then. --=20 Sergei --Sig_/Ti_i.wWF.BQk=eObnfk+q5+ Content-Type: application/pgp-signature Content-Description: Цифровая подпись OpenPGP -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQKTBAEBCgB9FiEE+g11JqJ4cL44QkmN7V5F4G8qwpMFAl07RRpfFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEZB MEQ3NTI2QTI3ODcwQkUzODQyNDk4REVENUU0NUUwNkYyQUMyOTMACgkQ7V5F4G8q wpPeHQ//XN6LblP4OgO9cPUKWv6cPSD0wicx5Q3IjoRwotBuP+NlcTOIq8Od7TzH ZsrPKpcaj+k944NQNqn1lJIbJCNl6rdB6VkufhiFf25C+6EdNlI7w+BUpUxJdTeH OZjseA/WLUpIcxzjagyb4UzR19G3scWcwmJ2UDi9DQjtPhTFAjv8N6VVTVAOwdpw 65E/AdVyQX8pI8k4vui+0uKonsA0TMTrU9cc92/prpM48/dgnm+Q5JLqX2QjbI39 XAOkwoim1Wgw7yBNK+nnWObUV34a0ESjDhZcTqfdfUD+nzEmR/wut5rzIDxQhpEL Awa90TGtEwRCeufRnnnJHOI2CUpbM8tvtSvuL7PUlAJVl9WnD60NySDiTY54IhBj yr0VvZuU7dsz3JWCDapUmRgV3gA0OfxtH8uURmlYIfBcE7VGFmIFRZ/YxMEaqaSq +9BaEuwx1D7L5VWBf9ksV8u6o7WGQw6lhl3Am78F63kQe1RV5mSwRKKtrca9h+ZB GpRK3Jmqgivk6ZO8/XzahQxv7pNLcUAwfIpEONMAB9haMfr0SB/Eq+AwPgEWQhxh QOtphUIxFyYmDFhImjhBqOWRFmvF2Lxb5uFgXhToh94tSXMQ3Ss+dE+eSsYLGmNx bMWjL8t1cZ2xcBnJhaNWlun/Fklb9+nsJJ5B4vGHBp88wrjJVrc= =WCLs -----END PGP SIGNATURE----- --Sig_/Ti_i.wWF.BQk=eObnfk+q5+-- From unknown Fri Jun 13 11:28:28 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Sat, 24 Aug 2019 11:24:07 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator