From patchwork Sun Feb 27 13:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 37517 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 3131327BBEA; Sun, 27 Feb 2022 14:02:56 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS 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 A347027BBE9 for ; Sun, 27 Feb 2022 14:02:55 +0000 (GMT) Received: from localhost ([::1]:42298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nOK8U-00040x-QD for patchwork@mira.cbaines.net; Sun, 27 Feb 2022 09:02:54 -0500 Received: from eggs.gnu.org ([209.51.188.92]:50676) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOK0w-0000Wc-AC for guix-patches@gnu.org; Sun, 27 Feb 2022 08:55:07 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:35057) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nOK0w-0001t9-1P for guix-patches@gnu.org; Sun, 27 Feb 2022 08:55:06 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nOK0w-0004ua-0m for guix-patches@gnu.org; Sun, 27 Feb 2022 08:55:06 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#54180] [PATCH 10/12] home: symlink-manager: 'cleanup-symlinks' uses 'file-system-fold'. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 27 Feb 2022 13:55:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54180 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54180@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 54180-submit@debbugs.gnu.org id=B54180.164597006918753 (code B ref 54180); Sun, 27 Feb 2022 13:55:05 +0000 Received: (at 54180) by debbugs.gnu.org; 27 Feb 2022 13:54:29 +0000 Received: from localhost ([127.0.0.1]:57174 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nOK0L-0004sJ-A5 for submit@debbugs.gnu.org; Sun, 27 Feb 2022 08:54:29 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44864) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nOK0B-0004qK-EB for 54180@debbugs.gnu.org; Sun, 27 Feb 2022 08:54:21 -0500 Received: from [2001:470:142:3::e] (port=50246 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nOK01-0001Zv-W0; Sun, 27 Feb 2022 08:54:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=NMW+/R/OsQyNgulr9QFBN2+8U0wHfw9yN+ObmtVobdc=; b=WPvt9jkXztkvBPToshkQ e+aCkfAeWyAht8wCxOP1/yjnxmFqDRWQcE3Q7tVsUbs4EYcXP9UCRQS4HYhKeXnBRHmpyG8OqNngu twPvkWCBVbup0D0lQzBkHvuMB9EjbqnIwJOrC7k77o/t2JAvCqDATgEKpZ5ep8z6bL6BxD+ImpcxE 3MEh9oc1c/N0XEFA6xshShJfd+P7wOqb+Nd/px2qn44NdjW8lEesS28em+j86E56d7GzmXV2BYggY DnFlgIOcs2kxStPXia1827onSltihg6WcTXdo4iwlgwlrRVdt6ob1GOjrZwS1/tAxkmKJx0FzpyjE qs7W/V/yJ/Dy8Q==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:55804 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nOK01-0007Pg-IS; Sun, 27 Feb 2022 08:54:09 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Sun, 27 Feb 2022 14:53:40 +0100 Message-Id: <20220227135342.10296-10-ludo@gnu.org> X-Mailer: git-send-email 2.34.0 In-Reply-To: <20220227135342.10296-1-ludo@gnu.org> References: <20220227135342.10296-1-ludo@gnu.org> 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 * gnu/home/services/symlink-manager.scm (update-symlinks-script)[cleanup-symlinks]: Take a home generation and iterate over its config files directly with 'file-system-fold'. Adjuster caller accordingly. Remove 'old-tree'. --- gnu/home/services/symlink-manager.scm | 107 ++++++++++++++------------ 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/gnu/home/services/symlink-manager.scm b/gnu/home/services/symlink-manager.scm index ba42424e8e..4f827c0360 100644 --- a/gnu/home/services/symlink-manager.scm +++ b/gnu/home/services/symlink-manager.scm @@ -118,51 +118,63 @@ (define (backup-file path) (rename-file (get-target-path path) (get-backup-path path)) (display (G_ " done\n"))) - (define (cleanup-symlinks old-tree) - ;; Delete from directory OLD-TREE symlinks that correspond to a - ;; previous generation. - (let ((to-delete ((file-tree-traverse #f) old-tree))) - (display - (G_ - "Cleaning up symlinks from previous home-environment.\n\n")) - (for-each - (match-lambda - (('dir . ".") - (display (G_ "Cleanup finished.\n\n"))) + (define (cleanup-symlinks home-generation) + ;; Delete from $HOME files that originate in HOME-GENERATION, the + ;; store item containing a home generation. + (define config-file-directory + ;; Note: Trailing slash is needed because "files" is a symlink. + (string-append home-generation "/files/")) - (('dir . directory) - (let ((directory (get-target-path directory))) - (catch 'system-error - (lambda () - (rmdir directory) - (format #t (G_ "Removed ~a.\n") directory)) - (lambda args - (let ((errno (system-error-errno args))) - (cond ((= ENOTEMPTY errno) - (format - #t - (G_ "Skipping ~a (not an empty directory)...\n") - directory)) - ((= ENOTDIR errno) - #t) - (else - (apply throw args)))))))) + (define (strip file) + (string-drop file + (+ 1 (string-length config-file-directory)))) - (('file . path) - (when (file-exists? (get-target-path path)) - ;; 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. - (if (symlink-to-store? (get-target-path path)) - (begin - (format #t (G_ "Removing ~a...") (get-target-path path)) - (delete-file (get-target-path path)) - (display (G_ " done\n"))) - (format - #t - (G_ "Skipping ~a (not a symlink to store)... done\n") - (get-target-path path)))))) - to-delete))) + (format #t (G_ "Cleaning up symlinks from previous home at ~a.~%") + home-generation) + (newline) + + (file-system-fold + (const #t) + (lambda (file stat _) ;leaf + (let ((file (get-target-path (strip file)))) + (when (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. + (if (symlink-to-store? file) + (begin + (format #t (G_ "Removing ~a...") file) + (delete-file file) + (display (G_ " done\n"))) + (format #t + (G_ "Skipping ~a (not a symlink to store)... done\n") + file))))) + + (const #t) ;down + (lambda (directory stat _) ;up + (unless (string=? directory config-file-directory) + (let ((directory (get-target-path (strip directory)))) + (catch 'system-error + (lambda () + (rmdir directory) + (format #t (G_ "Removed ~a.\n") directory)) + (lambda args + (let ((errno (system-error-errno args))) + (cond ((= ENOTEMPTY errno) + (format + #t + (G_ "Skipping ~a (not an empty directory)...\n") + directory)) + ((= ENOTDIR errno) #t) + (else + (apply throw args))))))))) + (const #t) ;skip + (const #t) ;error + #t ;init + config-file-directory + lstat) + + (display (G_ "Cleanup finished.\n\n"))) (define (create-symlinks new-tree new-files-path) ;; Create in directory NEW-TREE symlinks to the files under @@ -215,16 +227,11 @@ (define (get-source-path path) ;; to make file-system-tree works it should be a directory. (new-files-dir-path (string-append new-files-path "/.")) - (old-tree (if old-home - ((simplify-file-tree "") - (file-system-tree - (string-append old-home "/files/."))) - #f)) (new-tree ((simplify-file-tree "") (file-system-tree new-files-dir-path)))) - (when old-tree - (cleanup-symlinks old-tree)) + (when old-home + (cleanup-symlinks old-home)) (create-symlinks new-tree new-files-path)