From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id sFEtF+m4T2JYKAAAgWs5BA (envelope-from ) for ; Fri, 08 Apr 2022 06:24:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id wF5tFOm4T2IoDwEA9RJhRA (envelope-from ) for ; Fri, 08 Apr 2022 06:24:09 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 94DA7D364 for ; Fri, 8 Apr 2022 06:24:08 +0200 (CEST) Received: from localhost ([::1]:45154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncgAJ-0008JP-31 for larch@yhetil.org; Fri, 08 Apr 2022 00:24:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncgAE-0008JG-NU for guix-patches@gnu.org; Fri, 08 Apr 2022 00:24:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:39862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncgAE-0004v3-FF for guix-patches@gnu.org; Fri, 08 Apr 2022 00:24:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ncgAE-0004NC-AQ for guix-patches@gnu.org; Fri, 08 Apr 2022 00:24:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54762] [PATCH] home: symlink-manager: Use no-follow version of file-exists?. Resent-From: Andrew Tropin Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 08 Apr 2022 04:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54762 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxime Devos , 54762@debbugs.gnu.org Received: via spool by 54762-submit@debbugs.gnu.org id=B54762.164939182716789 (code B ref 54762); Fri, 08 Apr 2022 04:24:02 +0000 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 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-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1649391849; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=okXSfden+18NUBc80UQecK/RRzv83uTlTBVfrnDKwZM=; b=kvcel0h8Ym44AK+87bwOO8DIxVhEdhIGottHaaU9mU6K/bCpbj+TedqoXZLUE33ibYcwJv Yvi47mSycRUZZmDc1Q3y+cLvT4bELMCwsqlMhZUtesWH/9Xtr9Aq142QlemC3wDKjbyWf0 wYg5p1LIGgJLzvHzyCA4V7a/KSFQV5hGbZskHsisv5Ab9u+MTFuus4LILDxsA5zNoVXR4I viTsR3/f2Hv19/YizSX/wZ/Ry6s2zqlkyN9NOrxvTIVcOYvBhOn8N/sIjyvBxk9yRY6NQT Fuyp3EH3x6Ry7cJFvFClLIupF5xwr6pc0MCZhhVFT9trc6v+wQ/wQTPPVyWVmg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1649391849; a=rsa-sha256; cv=none; b=nM5qymSihr1qxSEJjyH9B2Y1cMw67tS/Hc18gBA35wYSutXsqaFUJF3U1LWV8Sk11l+Jpp +KPyTkv1q/BmTfhTaAJlGLLRIla20o0TcffGDsk4mqCOFJSQ4ArGobe8UWISjlbsM4XZX9 ugKGGSbh+64Tsz2S0rIiv9rJvci62deonyPzc3JDE045KckdVOd7Rw2KdIL0HKiQD68aE/ pqJptt5k8ymPAdkGafmgVAMUZhhvQdq+EXyTktsSWJSiBr9LPVU5DAp54/fOD1ZPfJkGyL EwaPYU8ikE7gadK7XRgy4zcMpBE8ZCPKoW7X77XGcKGg+uY3Xb2pclS2inM7GQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=jVmp2AQn; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -1.27 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=trop.in header.s=gm1 header.b=jVmp2AQn; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 94DA7D364 X-Spam-Score: -1.27 X-Migadu-Scanner: scn1.migadu.com X-TUID: A9SLDRI9XGVo --==-=-= 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----- --==-=-=--