From patchwork Wed Jun 7 22:09:52 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: 50756 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 81E6A27BBEA; Wed, 7 Jun 2023 23:11:18 +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 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 653C227BBE2 for ; Wed, 7 Jun 2023 23:11:16 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q71Mu-0005bZ-1B; Wed, 07 Jun 2023 18:11:04 -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 1q71Mt-0005bC-0i for guix-patches@gnu.org; Wed, 07 Jun 2023 18:11:03 -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 1q71Ms-00008O-Ow for guix-patches@gnu.org; Wed, 07 Jun 2023 18:11:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q71Ms-0007NL-Jw for guix-patches@gnu.org; Wed, 07 Jun 2023 18:11:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62264] [PATCH v2 1/3] store: Tolerate non-existent GC root directories. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 07 Jun 2023 22:11: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?= Received: via spool by 62264-submit@debbugs.gnu.org id=B62264.168617583828278 (code B ref 62264); Wed, 07 Jun 2023 22:11:02 +0000 Received: (at 62264) by debbugs.gnu.org; 7 Jun 2023 22:10:38 +0000 Received: from localhost ([127.0.0.1]:55118 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q71MT-0007M0-WD for submit@debbugs.gnu.org; Wed, 07 Jun 2023 18:10:38 -0400 Received: from eggs.gnu.org ([209.51.188.92]:53398) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q71MS-0007Lg-75 for 62264@debbugs.gnu.org; Wed, 07 Jun 2023 18:10:36 -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 1q71MM-00006m-0F; Wed, 07 Jun 2023 18:10:31 -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=w5CwL7aCKltgZRIlNiv7i64JnQjdLT+5SgD6yG+h3jY=; b=GyIdc50zTdSVfsVvvxnd 4dOtwT3PAyUvZ+rJeiPT+MxsL7hgTLFZHqlb0CH8Em9TZrBKkzKFmJfoTYtE/5b3bJ742X4NTo53J vU/kIVcrkf+omOvlKws+e/P5u2zCq6WwUigR4i6e8QtOzIEjhVoTzvCkOaj65ZXtU6yadvGPIV1Kb jGRO0k/i1VLvyaAoCZev2ddQ0aknq9cuXkqOJhujrWgw2PKhxLoxXe5gGXcHqKVcHXw9vlCIV9lX+ c0HQBas/A6sFEJ0JqRnlG+OQ05UbEM1CcmLWPS4Gc1w1PrtRvXqlsuLQQNF4nMxVLr+CsCF5IzwXm x3IsYGCdNGaccA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201] 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 1q71MJ-0007hQ-MQ; Wed, 07 Jun 2023 18:10:29 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 8 Jun 2023 00:09:52 +0200 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: <87zg5e27cd.fsf_-_@gnu.org> References: <87zg5e27cd.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(-) 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)))