From patchwork Fri Jun 16 14:26:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 50972 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 7931527BBE9; Fri, 16 Jun 2023 15:28:26 +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 48E5F27BBE2 for ; Fri, 16 Jun 2023 15:28:25 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qAAQo-0002LS-9z; Fri, 16 Jun 2023 10:28:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAAQm-0002L1-Od for guix-patches@gnu.org; Fri, 16 Jun 2023 10:28:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qAAQm-0005mJ-FB; Fri, 16 Jun 2023 10:28:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qAAQk-0002d6-B6; Fri, 16 Jun 2023 10:28:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62264] [PATCH v3 1/3] store: Tolerate non-existent GC root directories. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: mail@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 16 Jun 2023 14:28:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62264 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 62264@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 62264-submit@debbugs.gnu.org id=B62264.168692563710028 (code B ref 62264); Fri, 16 Jun 2023 14:28:02 +0000 Received: (at 62264) by debbugs.gnu.org; 16 Jun 2023 14:27:17 +0000 Received: from localhost ([127.0.0.1]:50134 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAAPz-0002bY-LV for submit@debbugs.gnu.org; Fri, 16 Jun 2023 10:27:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:48500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qAAPx-0002bH-S3 for 62264@debbugs.gnu.org; Fri, 16 Jun 2023 10:27:14 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAAPr-0005Lb-T3; Fri, 16 Jun 2023 10:27:07 -0400 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=dg6/V77AXuc+AHZ4EquFCUZe192xUXBH+haElhGMoYs=; b=V8pNkA7eblI8P8yvo9TS 3rWbQ/I/Rq2zKutu0dVoUZ4UJG2VMzlp/H0npIqaMivExHRhTfjQEf1fjZPDQmWheTN4c2S74FfeE Gpk3AA6ezE+w2HZGGBQtepgCyWkk+V63bJYvP0GDL1Tfm899qe2mfr0RwkhoFm+LbbD1rDg0TXKi5 7AjFLyZ4++cRFFN7soYwLsFW7SGR14AKKBAplTbA5IEirHpOBoG3+txnAct5rvxMAzHfZoHSUCBMV N1VVRj1nvg9Jr3rfcX7OnmGAXTC0nqxsAsQ0oXKzaqHdCSgMsiLhcvgIlSdVB11fG1bROE0dVYG+4 X0QfIGafALCXIw==; Received: from [193.50.110.184] (helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qAAPr-0005or-BY; Fri, 16 Jun 2023 10:27:07 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 16 Jun 2023 16:26:58 +0200 Message-Id: <9fa73252c3326376c4cca8dfe79deb5cea3de8fc.1686925582.git.ludo@gnu.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <87a5wzscuu.fsf_-_@gnu.org> References: <87a5wzscuu.fsf_-_@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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/store/roots.scm (gc-roots): Wrap 'scandir*' call in 'catch'. * tests/store-roots.scm ("gc-roots, initial"): New test. Move 'open-connection' call below. --- guix/store/roots.scm | 12 ++++++++++-- tests/store-roots.scm | 18 +++++++++++++++--- 2 files changed, 25 insertions(+), 5 deletions(-) base-commit: 31336e9f5d68512a9c1c6826bce9f17c892a2125 diff --git a/guix/store/roots.scm b/guix/store/roots.scm index 222f69c5c0..6b949b5a86 100644 --- a/guix/store/roots.scm +++ b/guix/store/roots.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2012, 2013, 2014, 2017, 2019 Ludovic Courtès +;;; Copyright © 2012-2014, 2017, 2019, 2023 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -105,7 +105,15 @@ (define (gc-roots) (map (match-lambda ((file . properties) (cons (scope file) properties))) - (scandir* directory regular?))))) + (catch 'system-error + (lambda () + (scandir* directory regular?)) + (lambda args + (if (= ENOENT + (system-error-errno + args)) + '() + (apply throw args)))))))) (loop (append rest (map first sub-directories)) (append (map canonical-root (filter symlink? files)) roots) diff --git a/tests/store-roots.scm b/tests/store-roots.scm index 5bcf1bc87e..9877987a65 100644 --- a/tests/store-roots.scm +++ b/tests/store-roots.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2019 Ludovic Courtès +;;; Copyright © 2019, 2023 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -21,14 +21,26 @@ (define-module (test-store-deduplication) #:use-module (guix store) #:use-module (guix store roots) #:use-module ((guix utils) #:select (call-with-temporary-directory)) + #:use-module ((guix build utils) #:select (delete-file-recursively)) + #:use-module ((guix config) #:select (%state-directory)) #:use-module (srfi srfi-1) #:use-module (srfi srfi-64)) -(define %store - (open-connection)) +(define %store #f) (test-begin "store-roots") +(test-equal "gc-roots, initial" + (list (string-append %state-directory "/profiles")) + (begin + ;; 'gc-roots' should gracefully handle lack of that directory. + (delete-file-recursively (string-append %state-directory "/profiles")) + (gc-roots))) + +;; The 'open-connection' call below gets guix-daemon to create +;; %STATE-DIRECTORY/profiles. +(set! %store (open-connection)) + (test-assert "gc-roots, regular root" (let* ((item (add-text-to-store %store "something" (random-text)))