From unknown Fri Jun 20 18:02:08 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#8374 <8374@debbugs.gnu.org> To: bug#8374 <8374@debbugs.gnu.org> Subject: Status: cp -a [-l] sometimes does not preserve timestamps of symlinks Reply-To: bug#8374 <8374@debbugs.gnu.org> Date: Sat, 21 Jun 2025 01:02:08 +0000 retitle 8374 cp -a [-l] sometimes does not preserve timestamps of symlinks reassign 8374 coreutils submitter 8374 Ruediger Meier severity 8374 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Tue Mar 29 12:30:12 2011 Received: (at submit) by debbugs.gnu.org; 29 Mar 2011 16:30:12 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q4bo3-00035v-Bl for submit@debbugs.gnu.org; Tue, 29 Mar 2011 12:30:12 -0400 Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q4ZG2-0007ib-3f for submit@debbugs.gnu.org; Tue, 29 Mar 2011 09:46:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4ZFv-0000oE-Sb for submit@debbugs.gnu.org; Tue, 29 Mar 2011 09:46:49 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable version=3.3.1 Received: from lists.gnu.org ([199.232.76.165]:46464) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4ZFv-0000o2-Dg for submit@debbugs.gnu.org; Tue, 29 Mar 2011 09:46:47 -0400 Received: from [140.186.70.92] (port=36932 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q4ZFq-0003O6-2T for bug-coreutils@gnu.org; Tue, 29 Mar 2011 09:46:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q4ZFg-0000lk-C4 for bug-coreutils@gnu.org; Tue, 29 Mar 2011 09:46:33 -0400 Received: from mx01.ffm1.treml-sturm.net ([217.68.2.100]:36730) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q4ZFg-0000il-74 for bug-coreutils@gnu.org; Tue, 29 Mar 2011 09:46:32 -0400 Received: from localhost (localhost [127.0.0.1]) by mx01.ffm1.treml-sturm.net (Postfix) with ESMTP id 7232F14599 for ; Tue, 29 Mar 2011 15:46:19 +0200 (CEST) Received: from wiesinginvestments.com (p5098db61.dip0.t-ipconnect.de [80.152.219.97]) by mx01.ffm1.treml-sturm.net (Postfix) with ESMTP id 4A90E13ED6 for ; Tue, 29 Mar 2011 15:46:09 +0200 (CEST) Received: from zappa.ga.local ([192.168.1.28]) by wiesinginvestments.com with Microsoft SMTPSVC(6.0.3790.4675); Tue, 29 Mar 2011 15:46:08 +0200 To: bug-coreutils@gnu.org Subject: cp -a [-l] sometimes does not preserve timestamps of symlinks Content-Disposition: inline From: Ruediger Meier Date: Tue, 29 Mar 2011 15:46:07 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201103291546.08007.ruediger.meier@ga-group.nl> X-OriginalArrivalTime: 29 Mar 2011 13:46:09.0007 (UTC) FILETIME=[A89337F0:01CBEE17] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 199.232.76.165 X-Spam-Score: -6.6 (------) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Tue, 29 Mar 2011 12:30:10 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -6.6 (------) Hi, I see you fixed that already for for cp -a http://marc.info/?t=124897089600001&r=1&w=2 But it does not together with option -link: cd /tmp/ ln -s somewhere symlink touch -h -t "197001010000" symlink cp -a symlink symlink-a cp -al symlink symlink-al ls -l symlink* lrwxrwxrwx 1 rudi users 9 1970-01-01 00:00 symlink -> somewhere lrwxrwxrwx 1 rudi users 9 1970-01-01 00:00 symlink-a -> somewhere lrwxrwxrwx 1 rudi users 9 2011-03-29 13:44 symlink-al -> somewhere I'm using core utils coreutils 8.9 (opensuse 11.4). BTW with coreutils 7.1 and 6.9 it behaves the other way, -al is correct but -a not. So probably -al is broken since you fixed -a in 7.5. cu, Rudi From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 31 10:12:22 2011 Received: (at 8374) by debbugs.gnu.org; 31 Mar 2011 14:12:23 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5Ibl-0001y1-8z for submit@debbugs.gnu.org; Thu, 31 Mar 2011 10:12:21 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Q5Ibi-0001xo-MZ for 8374@debbugs.gnu.org; Thu, 31 Mar 2011 10:12:19 -0400 Received: (qmail 5647 invoked from network); 31 Mar 2011 14:12:12 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 31 Mar 2011 14:12:12 -0000 Message-ID: <4D948B9E.8030100@draigBrady.com> Date: Thu, 31 Mar 2011 15:11:42 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Ruediger Meier Subject: Re: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks References: <201103291546.08007.ruediger.meier@ga-group.nl> In-Reply-To: <201103291546.08007.ruediger.meier@ga-group.nl> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8374 Cc: 8374@debbugs.gnu.org, Eric Blake X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 29/03/11 14:46, Ruediger Meier wrote: > Hi, > > > I see you fixed that already for for cp -a > http://marc.info/?t=124897089600001&r=1&w=2 > > But it does not together with option -link: > > cd /tmp/ > ln -s somewhere symlink > touch -h -t "197001010000" symlink > cp -a symlink symlink-a > cp -al symlink symlink-al > ls -l symlink* > lrwxrwxrwx 1 rudi users 9 1970-01-01 00:00 symlink -> somewhere > lrwxrwxrwx 1 rudi users 9 1970-01-01 00:00 symlink-a -> somewhere > lrwxrwxrwx 1 rudi users 9 2011-03-29 13:44 symlink-al -> somewhere > > > I'm using core utils coreutils 8.9 (opensuse 11.4). > > BTW with coreutils 7.1 and 6.9 it behaves the other way, -al is correct > but -a not. > > So probably -al is broken since you fixed -a in 7.5. Hmm it looks now like we're creating symlinks (with wrong timestamps), but in fact we should be creating hardlinks to symlinks. This seems to have been changed with: http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=3346c0af Eric do you have any suggestions? The following seems to make things work as expected diff --git a/src/copy.c b/src/copy.c index a672fd3..4f07d2c 100644 --- a/src/copy.c +++ b/src/copy.c @@ -2226,8 +2226,7 @@ copy_internal (char const *src_name, char const *dst_name, where link(2) follows the link, gnulib creates a symlink with identical contents, which is good enough for our purposes). */ else if (x->hard_link - && (!S_ISLNK (src_mode) - || x->dereference != DEREF_NEVER)) + && !(S_ISLNK (src_mode) && x->dereference != DEREF_NEVER)) { if (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, 0)) { Hmm, maybe it's better to skip linkat() for symlinks altogether since the gnulib fallback on systems that implicitly dereference, will create symlinks, but without the right timestamps. Or, perhaps the gnulib fallback should try to update timestamps too? cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 31 10:20:29 2011 Received: (at 8374) by debbugs.gnu.org; 31 Mar 2011 14:20:29 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5Ija-00029r-SI for submit@debbugs.gnu.org; Thu, 31 Mar 2011 10:20:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5IjY-00029f-MC for 8374@debbugs.gnu.org; Thu, 31 Mar 2011 10:20:26 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2VEKITH014964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 31 Mar 2011 10:20:18 -0400 Received: from [10.3.113.87] (ovpn-113-87.phx2.redhat.com [10.3.113.87]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p2VEKHHG027516; Thu, 31 Mar 2011 10:20:17 -0400 Message-ID: <4D948DA0.9080904@redhat.com> Date: Thu, 31 Mar 2011 08:20:16 -0600 From: Eric Blake Organization: Red Hat User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.9 MIME-Version: 1.0 To: =?ISO-8859-1?Q?P=E1draig_Brady?= Subject: Re: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks References: <201103291546.08007.ruediger.meier@ga-group.nl> <4D948B9E.8030100@draigBrady.com> In-Reply-To: <4D948B9E.8030100@draigBrady.com> X-Enigmail-Version: 1.1.2 OpenPGP: url=http://people.redhat.com/eblake/eblake.gpg Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enig82607691CE2742DFC48B0D52" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Spam-Score: -10.3 (----------) X-Debbugs-Envelope-To: 8374 Cc: 8374@debbugs.gnu.org, bug-gnulib , Ruediger Meier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -10.3 (----------) This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig82607691CE2742DFC48B0D52 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable [adding bug-gnulib] On 03/31/2011 08:11 AM, P=E1draig Brady wrote: >> So probably -al is broken since you fixed -a in 7.5. >=20 > Hmm it looks now like we're creating symlinks (with wrong timestamps), > but in fact we should be creating hardlinks to symlinks. >=20 > This seems to have been changed with: > http://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dcommit;h=3D3346c0af= >=20 > Eric do you have any suggestions? > The following seems to make things work as expected >=20 > diff --git a/src/copy.c b/src/copy.c > index a672fd3..4f07d2c 100644 > --- a/src/copy.c > +++ b/src/copy.c > @@ -2226,8 +2226,7 @@ copy_internal (char const *src_name, char const *= dst_name, > where link(2) follows the link, gnulib creates a symlink with > identical contents, which is good enough for our purposes). */ > else if (x->hard_link > - && (!S_ISLNK (src_mode) > - || x->dereference !=3D DEREF_NEVER)) > + && !(S_ISLNK (src_mode) && x->dereference !=3D DEREF_NEVER)= ) > { > if (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, 0)) > { >=20 > Hmm, maybe it's better to skip linkat() for symlinks altogether > since the gnulib fallback on systems that implicitly dereference, > will create symlinks, but without the right timestamps. > Or, perhaps the gnulib fallback should try to update timestamps too? Sounds to me like the gnulib fallback should be made smarter. Which systems lack linkat() but have the capability to set timestamps? BSD? But the original report was about opensuse, which is Linux based, and my recollection is that Linux handles hardlinks to symlinks much longer than it could set symlink timestamps. --=20 Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org --------------enig82607691CE2742DFC48B0D52 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJNlI2gAAoJEKeha0olJ0NqRXsH/i96P7s94L0jgUx2m6U2YC6O Dhw8yEAsZVuasa/2QbS6GEHrxU3wSESj3rd4tLEH3n7KTA79+AU0rqIHcESwW2LK s+u+dAJPiJJ1ytsKyY9ZbDptodnYicRL9lPPdLZZymIhoDK7WYv0yNv/+YChS+N3 Wc10I5ThQZg83BbyJNVvy9/9xbIbQ2m6nJJUOWPgZ5aFlGoBPC5Cw/XtctIxcDLt WeenwpLjdvYeOgq48Adjb8F7mzXuv9sRF+yIXzdO2bU994Ot4JaTT0hkDLtUAALp toEwrdzhC6f1NoV7llx0T3oL4/JMRVEd9/kg9N238pRmKMRmfJeB2t0VtnBdYQw= =nP7N -----END PGP SIGNATURE----- --------------enig82607691CE2742DFC48B0D52-- From debbugs-submit-bounces@debbugs.gnu.org Thu Mar 31 10:59:29 2011 Received: (at 8374) by debbugs.gnu.org; 31 Mar 2011 14:59:29 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5JLM-00030v-EB for submit@debbugs.gnu.org; Thu, 31 Mar 2011 10:59:28 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Q5JLK-00030i-1a for 8374@debbugs.gnu.org; Thu, 31 Mar 2011 10:59:26 -0400 Received: (qmail 15720 invoked from network); 31 Mar 2011 14:59:20 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 31 Mar 2011 14:59:20 -0000 Message-ID: <4D9496AA.5010804@draigBrady.com> Date: Thu, 31 Mar 2011 15:58:50 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Eric Blake Subject: Re: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks References: <201103291546.08007.ruediger.meier@ga-group.nl> <4D948B9E.8030100@draigBrady.com> <4D948DA0.9080904@redhat.com> In-Reply-To: <4D948DA0.9080904@redhat.com> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8374 Cc: 8374@debbugs.gnu.org, bug-gnulib , Ruediger Meier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) On 31/03/11 15:20, Eric Blake wrote: > Sounds to me like the gnulib fallback should be made smarter. Which > systems lack linkat() but have the capability to set timestamps? BSD? > But the original report was about opensuse, which is Linux based, and my > recollection is that Linux handles hardlinks to symlinks much longer > than it could set symlink timestamps. When you put it like that, then it's probably not worth worrying about updating timestamps in gnulib, when it's probably not even possible. cheers, Pádraig. From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 01 07:09:39 2011 Received: (at 8374) by debbugs.gnu.org; 1 Apr 2011 11:09:39 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5cEV-0005Ap-AH for submit@debbugs.gnu.org; Fri, 01 Apr 2011 07:09:39 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Q5cES-0005Ac-8h for 8374@debbugs.gnu.org; Fri, 01 Apr 2011 07:09:38 -0400 Received: (qmail 9132 invoked from network); 1 Apr 2011 11:09:29 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 1 Apr 2011 11:09:29 -0000 Message-ID: <4D95B247.1020109@draigBrady.com> Date: Fri, 01 Apr 2011 12:08:55 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 To: Ruediger Meier Subject: Re: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks References: <201103291546.08007.ruediger.meier@ga-group.nl> <4D948B9E.8030100@draigBrady.com> In-Reply-To: <4D948B9E.8030100@draigBrady.com> X-Enigmail-Version: 1.0.1 Content-Type: multipart/mixed; boundary="------------080501090005080309030608" X-Spam-Score: -2.7 (--) X-Debbugs-Envelope-To: 8374 Cc: 8374@debbugs.gnu.org, Eric Blake X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.7 (--) This is a multi-part message in MIME format. --------------080501090005080309030608 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit On 31/03/11 15:11, Pádraig Brady wrote: > On 29/03/11 14:46, Ruediger Meier wrote: >> Hi, >> >> >> I see you fixed that already for for cp -a >> http://marc.info/?t=124897089600001&r=1&w=2 >> >> But it does not together with option -link: >> >> cd /tmp/ >> ln -s somewhere symlink >> touch -h -t "197001010000" symlink >> cp -a symlink symlink-a >> cp -al symlink symlink-al >> ls -l symlink* >> lrwxrwxrwx 1 rudi users 9 1970-01-01 00:00 symlink -> somewhere >> lrwxrwxrwx 1 rudi users 9 1970-01-01 00:00 symlink-a -> somewhere >> lrwxrwxrwx 1 rudi users 9 2011-03-29 13:44 symlink-al -> somewhere >> >> >> I'm using core utils coreutils 8.9 (opensuse 11.4). >> >> BTW with coreutils 7.1 and 6.9 it behaves the other way, -al is correct >> but -a not. >> >> So probably -al is broken since you fixed -a in 7.5. > > Hmm it looks now like we're creating symlinks (with wrong timestamps), > but in fact we should be creating hardlinks to symlinks. > > This seems to have been changed with: > http://git.sv.gnu.org/gitweb/?p=coreutils.git;a=commit;h=3346c0af That commit didn't actually change the logic as far as I can see. It was actually ca9e212c that introduced the logic bug I think. So I'm going to apply the attached. cheers, Pádraig. --------------080501090005080309030608 Content-Type: text/x-patch; name="cp-al-timestamps.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cp-al-timestamps.diff" >From 533b834ab52682945569e1bc1e61624a09a34273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Thu, 31 Mar 2011 11:28:58 +0100 Subject: [PATCH] copy: link rather than copy symlinks, when --link used This bug was introduced in commit ca9e212c, 2009-09-24, "cp, mv: use linkat to guarantee semantics", which inadvertently disabled the creation of hardlinks to symlinks. However rather than implementing the intention of that commit and relying on gnulib linkat emulation, we'll revert to the previous emulation as that maintains ownership and timestamps. * src/copy.c (copy_internal): Use our existing hardlink to symlink emulation when we're not sure that link() will not dereference the symlink. Also ensure that we copy the timestamps of the original symlink when we use the emulation. * tests/cp/link-symlink: Add a test to ensure timestamps copied. * tests/Makefile.am: Reference the new test. * NEWS: Mention the fix. Reported by Ruediger Meier --- NEWS | 4 ++++ src/copy.c | 27 ++++++++++++++++++++------- tests/Makefile.am | 1 + tests/cp/link-symlink | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 7 deletions(-) create mode 100755 tests/cp/link-symlink diff --git a/NEWS b/NEWS index 6d66355..f25a696 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,10 @@ GNU coreutils NEWS -*- outline -*- wc would dereference a NULL pointer upon an early out-of-memory error [bug introduced in coreutils-7.1] + cp -a --link would not create a hardlink to a symlink, instead + copying the symlink and then not preserving its timestamp. + [bug introduced in coreutils-8.0] + ** New features dd now accepts the 'nocache' flag to the iflag and oflag options, diff --git a/src/copy.c b/src/copy.c index 104652d..e839f97 100644 --- a/src/copy.c +++ b/src/copy.c @@ -2169,13 +2169,24 @@ copy_internal (char const *src_name, char const *dst_name, } } - /* cp, invoked with `--link --no-dereference', should not follow the - link; we guarantee this with gnulib's linkat module (on systems - where link(2) follows the link, gnulib creates a symlink with - identical contents, which is good enough for our purposes). */ + /* POSIX 2008 states that it is implementation-defined whether + link() on a symlink creates a hard-link to the symlink, or only + to the referent (effectively dereferencing the symlink) (POSIX + 2001 required the latter behavior, although many systems provided + the former). Yet cp, invoked with `--link --no-dereference', + should not follow the link. We can approximate the desired + behavior by skipping this hard-link creating block and instead + copying the symlink, via the `S_ISLNK'- copying code below. + LINK_FOLLOWS_SYMLINKS is tri-state; if it is -1, we don't know + how link() behaves, so we use the fallback case for safety. + + Note gnulib's linkat module, guarantees that the symlink is not + dereferenced. However its emulation currently doesn't maintain + timestamps or ownership so we only call it when we know the + emulation will not be needed. */ else if (x->hard_link - && (!S_ISLNK (src_mode) - || x->dereference != DEREF_NEVER)) + && !(LINK_FOLLOWS_SYMLINKS && S_ISLNK (src_mode) + && x->dereference == DEREF_NEVER)) { if (linkat (AT_FDCWD, src_name, AT_FDCWD, dst_name, 0)) { @@ -2298,7 +2309,9 @@ copy_internal (char const *src_name, char const *dst_name, /* If we've just created a hard-link due to cp's --link option, we're done. */ - if (x->hard_link && ! S_ISDIR (src_mode)) + if (x->hard_link && ! S_ISDIR (src_mode) + && !(LINK_FOLLOWS_SYMLINKS && S_ISLNK (src_mode) + && x->dereference == DEREF_NEVER)) return delayed_ok; if (copied_as_regular) diff --git a/tests/Makefile.am b/tests/Makefile.am index 99b46e8..e7f3fff 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -328,6 +328,7 @@ TESTS = \ cp/link \ cp/link-no-deref \ cp/link-preserve \ + cp/link-symlink \ cp/no-deref-link1 \ cp/no-deref-link2 \ cp/no-deref-link3 \ diff --git a/tests/cp/link-symlink b/tests/cp/link-symlink new file mode 100755 index 0000000..443b337 --- /dev/null +++ b/tests/cp/link-symlink @@ -0,0 +1,41 @@ +#!/bin/sh +# Ensure that cp -a --link maintains timestamps if possible + +# Copyright (C) 2011 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 . + +. "${srcdir=.}/init.sh"; path_prepend_ ../src +print_ver_ cp + +# Check that the timestamps of the symlink are copied +# if we're using hardlink to symlink emulation. +touch file +ln -s file link || framework_failure +touch -m -h -d 2011-01-01 link || + skip_test_ "Your system doesn't support updating symlink timestamps" +case `stat --format=%y link` in + 2011-01-01*) ;; + *) skip_test_ "Your system doesn't support updating symlink timestamps" ;; +esac + +# link.cp is probably a hardlink, but may also be a symlink +# In either case the timestamp should match the original. +cp -al link link.cp +case `stat --format=%y link.cp` in + 2011-01-01*) ;; + *) fail=1 ;; +esac + +Exit $fail -- 1.7.4 --------------080501090005080309030608-- From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 01 08:21:49 2011 Received: (at 8374) by debbugs.gnu.org; 1 Apr 2011 12:21:49 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5dML-0007Zl-Ev for submit@debbugs.gnu.org; Fri, 01 Apr 2011 08:21:49 -0400 Received: from mx.meyering.net ([82.230.74.64]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5dM9-0007ZL-Op for 8374@debbugs.gnu.org; Fri, 01 Apr 2011 08:21:47 -0400 Received: by rho.meyering.net (Acme Bit-Twister, from userid 1000) id C23D66049F; Fri, 1 Apr 2011 14:21:29 +0200 (CEST) From: Jim Meyering To: =?iso-8859-1?Q?P=E1draig?= Brady Subject: Re: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks In-Reply-To: <4D95B247.1020109@draigBrady.com> (=?iso-8859-1?Q?=22P=E1drai?= =?iso-8859-1?Q?g?= Brady"'s message of "Fri, 01 Apr 2011 12:08:55 +0100") References: <201103291546.08007.ruediger.meier@ga-group.nl> <4D948B9E.8030100@draigBrady.com> <4D95B247.1020109@draigBrady.com> Date: Fri, 01 Apr 2011 14:21:29 +0200 Message-ID: <87oc4qjh6e.fsf@rho.meyering.net> Lines: 59 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Spam-Score: -5.9 (-----) X-Debbugs-Envelope-To: 8374 Cc: 8374@debbugs.gnu.org, Eric Blake , Ruediger Meier X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -5.9 (-----) P=E1draig Brady wrote: ... >> Hmm it looks now like we're creating symlinks (with wrong timestamps), >> but in fact we should be creating hardlinks to symlinks. >> >> This seems to have been changed with: >> http://git.sv.gnu.org/gitweb/?p=3Dcoreutils.git;a=3Dcommit;h=3D3346c0af > > That commit didn't actually change the logic as far as I can see. > It was actually ca9e212c that introduced the logic bug I think. > > So I'm going to apply the attached. ... > Subject: [PATCH] copy: link rather than copy symlinks, when --link used > > This bug was introduced in commit ca9e212c, 2009-09-24, > "cp, mv: use linkat to guarantee semantics", which > inadvertently disabled the creation of hardlinks to symlinks. > However rather than implementing the intention of that commit > and relying on gnulib linkat emulation, we'll revert to the > previous emulation as that maintains ownership and timestamps. > > * src/copy.c (copy_internal): Use our existing hardlink to > symlink emulation when we're not sure that link() will > not dereference the symlink. Also ensure that we copy the How about "...when link() might dereference..." > timestamps of the original symlink when we use the emulation. > * tests/cp/link-symlink: Add a test to ensure timestamps copied. > * tests/Makefile.am: Reference the new test. > * NEWS: Mention the fix. > Reported by Ruediger Meier > --- > NEWS | 4 ++++ > src/copy.c | 27 ++++++++++++++++++++------- > tests/Makefile.am | 1 + > tests/cp/link-symlink | 41 +++++++++++++++++++++++++++++++++++++++++ > 4 files changed, 66 insertions(+), 7 deletions(-) > create mode 100755 tests/cp/link-symlink > > diff --git a/NEWS b/NEWS > index 6d66355..f25a696 100644 > --- a/NEWS > +++ b/NEWS > @@ -20,6 +20,10 @@ GNU coreutils NEWS = -*- outline -*- > wc would dereference a NULL pointer upon an early out-of-memory error > [bug introduced in coreutils-7.1] > > + cp -a --link would not create a hardlink to a symlink, instead > + copying the symlink and then not preserving its timestamp. > + [bug introduced in coreutils-8.0] Please move that "up" so they're alphabetized. > dd now accepts the 'nocache' flag to the iflag and oflag options, > diff --git a/src/copy.c b/src/copy.c Thanks for fixing that! From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 01 09:56:06 2011 Received: (at 8374-done) by debbugs.gnu.org; 1 Apr 2011 13:56:06 +0000 Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q5epa-0001Jl-A0 for submit@debbugs.gnu.org; Fri, 01 Apr 2011 09:56:06 -0400 Received: from mail1.slb.deg.dub.stisp.net ([84.203.253.98]) by debbugs.gnu.org with smtp (Exim 4.69) (envelope-from ) id 1Q5epX-0001J7-Ni for 8374-done@debbugs.gnu.org; Fri, 01 Apr 2011 09:56:04 -0400 Received: (qmail 42010 invoked from network); 1 Apr 2011 13:55:57 -0000 Received: from unknown (HELO ?192.168.2.25?) (84.203.137.218) by mail1.slb.deg.dub.stisp.net with SMTP; 1 Apr 2011 13:55:57 -0000 Message-ID: <4D95D94A.9090609@draigBrady.com> Date: Fri, 01 Apr 2011 14:55:22 +0100 From: =?ISO-8859-1?Q?P=E1draig_Brady?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.8) Gecko/20100227 Thunderbird/3.0.3 MIME-Version: 1.0 Subject: Re: bug#8374: cp -a [-l] sometimes does not preserve timestamps of symlinks References: <201103291546.08007.ruediger.meier@ga-group.nl> <4D948B9E.8030100@draigBrady.com> <4D95B247.1020109@draigBrady.com> <87oc4qjh6e.fsf@rho.meyering.net> In-Reply-To: <87oc4qjh6e.fsf@rho.meyering.net> X-Enigmail-Version: 1.0.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Spam-Score: -2.0 (--) X-Debbugs-Envelope-To: 8374-done Cc: 8374-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: debbugs-submit-bounces@debbugs.gnu.org Errors-To: debbugs-submit-bounces@debbugs.gnu.org X-Spam-Score: -2.0 (--) On 01/04/11 13:21, Jim Meyering wrote: >> * src/copy.c (copy_internal): Use our existing hardlink to >> symlink emulation when we're not sure that link() will >> not dereference the symlink. Also ensure that we copy the > > How about "...when link() might dereference..." Much clearer thanks. I've pushed that. From unknown Fri Jun 20 18:02:08 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, 30 Apr 2011 11:24:04 +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