From patchwork Thu Apr 7 08:22:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Tropin X-Patchwork-Id: 38372 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 36BBC27BBEA; Thu, 7 Apr 2022 10:08:21 +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=unavailable 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 B8A1727BBE9 for ; Thu, 7 Apr 2022 10:08:20 +0100 (BST) Received: from localhost ([::1]:43894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ncO7n-00007r-S3 for patchwork@mira.cbaines.net; Thu, 07 Apr 2022 05:08:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51842) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncO7W-00007b-St for guix-patches@gnu.org; Thu, 07 Apr 2022 05:08:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37708) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ncO7W-0003ub-Jb for guix-patches@gnu.org; Thu, 07 Apr 2022 05:08:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ncO7W-0007Ow-Ek for guix-patches@gnu.org; Thu, 07 Apr 2022 05:08: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: Thu, 07 Apr 2022 09:08:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 54762 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54762@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.164932246528425 (code B ref -1); Thu, 07 Apr 2022 09:08:02 +0000 Received: (at submit) by debbugs.gnu.org; 7 Apr 2022 09:07:45 +0000 Received: from localhost ([127.0.0.1]:59838 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ncO7F-0007OP-1M for submit@debbugs.gnu.org; Thu, 07 Apr 2022 05:07:45 -0400 Received: from lists.gnu.org ([209.51.188.17]:59652) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ncO7D-0007OI-Oe for submit@debbugs.gnu.org; Thu, 07 Apr 2022 05:07:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51806) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncO7D-00005j-JX for guix-patches@gnu.org; Thu, 07 Apr 2022 05:07:43 -0400 Received: from relay5-d.mail.gandi.net ([217.70.183.197]:50283) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ncO7A-0003sC-Cj for guix-patches@gnu.org; Thu, 07 Apr 2022 05:07:43 -0400 Received: (Authenticated sender: andrew@trop.in) by mail.gandi.net (Postfix) with ESMTPSA id E79E81C000F for ; Thu, 7 Apr 2022 09:07:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=trop.in; s=gm1; t=1649322456; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=rSv6pD3gnTqFUXI0QPlTCOjl1m8sq3aKV9O+hqhJDLM=; b=iW8Hr92LrXhFY97d/uT1UoYQO5mmRMrfvmnpQQNCmJ0WNGLOI2LQPv/rDL7U+T5LhdMtil +W36luQCidXy3gh4rb16iUte3KIocaLPoCAyGIcMOjdvPel0CmQh/wv4aQlctLWFI8zWtS oW6qwFv6QVxH9iY+Ry/pTyZPgoPYLfB/x959vDeJrZdUiFa+ujMX46OdHLZ+QAERWu/CvY v+8lT/CaOLz8j/URsz8mqopv2KS3IKVP/g8bXUFxiWN7Lr3tPBMGgukhzqFUlKr95Tjn+q 2t66qO06trH7X21gka0qEUMEgOLST9wpCNmqwhPGFBf6Kt0y8O1wjdz3AznfpQ== From: Andrew Tropin Date: Thu, 7 Apr 2022 11:22:48 +0300 Message-ID: <87zgkxxnvv.fsf@trop.in> MIME-Version: 1.0 Received-SPF: pass client-ip=217.70.183.197; envelope-from=andrew@trop.in; helo=relay5-d.mail.gandi.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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 * gnu/home/services/symlink-manager.scm (update-symlinks-script): Use no-follow version of file-exists?. --- file-exists? returns #f on dangling symlinks, which makes such files "invisible" during the cleanup process and breaks activation of home environment. gnu/home/services/symlink-manager.scm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gnu/home/services/symlink-manager.scm b/gnu/home/services/symlink-manager.scm index 6d19258ec7..bb67152e5b 100644 --- a/gnu/home/services/symlink-manager.scm +++ b/gnu/home/services/symlink-manager.scm @@ -85,6 +85,13 @@ (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." + (or (file-exists? file) + (and=> (false-if-exception (lstat file)) + (lambda (x) + (equal? (stat:type x) 'symlink))))) + (define (symlink-to-store? file) (catch 'system-error (lambda () @@ -123,7 +130,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 +190,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 +199,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)))