From debbugs-submit-bounces@debbugs.gnu.org Fri Apr 08 00:23:47 2022 Received: (at 54762) by debbugs.gnu.org; 8 Apr 2022 04:23:47 +0000 Received: from localhost ([127.0.0.1]:33759 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ncg9z-0004Mi-1n for submit@debbugs.gnu.org; Fri, 08 Apr 2022 00:23:47 -0400 Received: from relay3-d.mail.gandi.net ([217.70.183.195]:47429) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ncg9x-0004MT-66 for 54762@debbugs.gnu.org; Fri, 08 Apr 2022 00:23:46 -0400 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id 1C42A60005; Fri, 8 Apr 2022 04:23:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1649391818; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=okXSfden+18NUBc80UQecK/RRzv83uTlTBVfrnDKwZM=; b=jVmp2AQnI777SkJVwKB/h4NrJuFaKaU8EKMCZ2RmWb8qOkRlL5XZT0uVZDEB24R/lEEFja +bAdo3q+8PLFweGwPF2dWkg5ejOXStgW8rHJgvZs2g/mB7PzU/E3duFAVaKWAnO5sy2PFL 4bOJx4yaKURKFjd7yL/yoKkOLhdW9FkNqICCOQNFkrfci/+C5zXZotuRWqg2iRIqZZdnMa JIBSdACtmtUSsQg2w6ebZtm4whyeZc4ZSQxLLmePqEBjUIm+YVS0fe51vP3BNxyBdj5bUr bAp5OZNUYqw2FVb7v0KsU6fSbIu62yDm6Wh9KNcbekLmnvb60MzUrDd2UhDURw== From: Andrew Tropin To: Maxime Devos , 54762@debbugs.gnu.org Subject: Re: [bug#54762] [PATCH] home: symlink-manager: Use no-follow version of file-exists?. In-Reply-To: References: <87zgkxxnvv.fsf@trop.in> <67cab598e57ecf7cf930d4b2d0568fd2f2f6f95d.camel@telenet.be> <87bkxc6d5t.fsf@trop.in> Date: Fri, 08 Apr 2022 07:23:34 +0300 Message-ID: <878rsg5hkp.fsf@trop.in> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 54762 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: -1.7 (-) --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 2022-04-07 20:21, Maxime Devos wrote: > Andrew Tropin schreef op do 07-04-2022 om 20:01 [+0300]: >> Idk how file-exists? works internally, but still expect it to be more >> efficient than lstat.=C2=A0 That's why I decided to use lstat only as a >> "fallback" option in `or` statement. > > Here's the definition, from module/ice-9/boot-9.scm (Guile source > code): > > ;; For reference, Emacs file-exists-p uses stat in this same way. > (define file-exists? > (if (provided? 'posix) > (lambda (str) > (->bool (stat str #f))) > [non-POSIX code that's not relevant to Guix])) > > 'file-exists?' just calls 'stat', a variant of 'lstat', so I don't > think there are performance gains to be had here. Well, the > (stat ... #f) might not need to install an exception handler since it > is written in C, but that seems at most a micro-optimisation to me. > > Greetings, > Maxime. Updated the implementation, which behaves similiar to file-exists?, but not follow symlinks. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=v2-0001-home-symlink-manager-Use-no-follow-version-of-fil.patch Content-Transfer-Encoding: quoted-printable From=2092ee52a96d536cba2b3b473f99e8f36646da81fd Mon Sep 17 00:00:00 2001 From: Andrew Tropin Date: Thu, 7 Apr 2022 11:22:48 +0300 Subject: [PATCH v2] home: symlink-manager: Use no-follow version of file-exists?. * gnu/home/services/symlink-manager.scm (update-symlinks-script): Use no-follow version of file-exists?. =2D-- gnu/home/services/symlink-manager.scm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/gnu/home/services/symlink-manager.scm b/gnu/home/services/syml= ink-manager.scm index 6d19258ec7..e4c931fbee 100644 =2D-- a/gnu/home/services/symlink-manager.scm +++ b/gnu/home/services/symlink-manager.scm @@ -85,6 +85,10 @@ (define (target-file file) ;; such as "config/fontconfig/fonts.conf" or "bashrc". (string-append home-directory "/" (preprocess-file file))) =20 + (define (no-follow-file-exists? file) + "Return #t if file exists, even if it's a dangling symlink." + (->bool (false-if-exception (lstat file)))) + (define (symlink-to-store? file) (catch 'system-error (lambda () @@ -123,7 +127,7 @@ (define (strip file) (const #t) (lambda (file stat _) ;leaf (let ((file (target-file (strip file)))) =2D (when (file-exists? file) + (when (no-follow-file-exists? file) ;; DO NOT remove the file if it is no longer a symlink to ;; the store, it will be backed up later during ;; create-symlinks phase. @@ -183,7 +187,7 @@ (define (source-file file) (lambda (file stat result) ;leaf (let ((source (source-file (strip file))) (target (target-file (strip file)))) =2D (when (file-exists? target) + (when (no-follow-file-exists? target) (backup-file (strip file))) (format #t (G_ "Symlinking ~a -> ~a...") target source) @@ -192,7 +196,7 @@ (define (source-file file) (lambda (directory stat result) ;down (unless (string=3D? directory config-file-directory) (let ((target (target-file (strip directory)))) =2D (when (and (file-exists? target) + (when (and (no-follow-file-exists? target) (not (file-is-directory? target))) (backup-file (strip directory))) =20 =2D-=20 2.34.0 --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable =2D-=20 Best regards, Andrew Tropin --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJDBAEBCgAtFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmJPuMYPHGFuZHJld0B0 cm9wLmluAAoJECII0glYwd6wKD4P/Rc4+9sXARQUG3OSRTnLyLGO8UHO+3RQHxiW rwBsb6OtWC1oCQjTxufGjU/xeCDWtwxAE+V8UTYB3WMfqPrRXfWjVLR8/3LW27dm UIFLh34dtqC9rkLjrgOH43fDgLkmxwjuGf2k6hdpDtsv010pu3oSTVFftDejAp/Z pnkENfcSvcCjuwPcFel+4VSW7+pke9N8VXPFEIMj5JhyxZ0z5d5wtuGV0doW8l4C k153QB5VouZ4+AFSRQLDGdzqaTpgs7KBnbF0jlkve8Gz/WjMQvr0ErIeUTOzNdEW Ku6OondiTQQJpnJFm1pqvKB/tztxTKZBEs7rJMM1UPmu7lgrdbYTNlq7OP3xmLb5 UbiKLsjnJaNKZnqqJDarCLhatMthHKQT5txU84cAit3BvpS3PwBjYRoSuMlLjRvb A3POs3AXd6bqXTycMeeOA8mck7KbeYC8m5i6trvb/76bN0m/I/E46HAF0s1Ojmbh fkEny4qbhwqa3KSFLSwZeldZnpzIsdlTf3O6aL/o44fIBUK4IDXGI9/7gm8bEpwZ I/Ws5hH6T3ThbpQ9HO75KNT7z1hD8d6JaB55VZQS2+wMbMzOZT4wR8drWqvds+IP QOsbWME9lA+imLMsVQ4CS8bJIEBapEK8Qk7F9uM455ssPFehUFgYvQwLvuzHrE/+ pGGSxIW9 =WHvJ -----END PGP SIGNATURE----- --==-=-=--