From patchwork Fri Apr 8 04:23:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 38388 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8C22C27BBEB; Fri, 8 Apr 2022 05:24:12 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id ECA7327BBEA for ; Fri, 8 Apr 2022 05:24:09 +0100 (BST) Received: from localhost ([::1]:45154 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncgAL-0008JP-3N for patchwork@mira.cbaines.net; Fri, 08 Apr 2022 00:24:09 -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 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches 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.  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. From 92ee52a96d536cba2b3b473f99e8f36646da81fd 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?. --- 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/symlink-manager.scm index 6d19258ec7..e4c931fbee 100644 --- 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))) + (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)))) - (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)))) - (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=? directory config-file-directory) (let ((target (target-file (strip directory)))) - (when (and (file-exists? target) + (when (and (no-follow-file-exists? target) (not (file-is-directory? target))) (backup-file (strip directory))) -- 2.34.0