From patchwork Tue May 19 07:23:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janneke Nieuwenhuizen X-Patchwork-Id: 22204 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 761B127BBE3; Tue, 19 May 2020 08:24:11 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=unavailable autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTP id 0FF4C27BBE1 for ; Tue, 19 May 2020 08:24:11 +0100 (BST) Received: from localhost ([::1]:54792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jawbi-0006Fm-Kz for patchwork@mira.cbaines.net; Tue, 19 May 2020 03:24:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jawbb-0006D3-3P for guix-patches@gnu.org; Tue, 19 May 2020 03:24:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:37496) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jawba-0000hQ-QH for guix-patches@gnu.org; Tue, 19 May 2020 03:24:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jawba-0003s1-N5 for guix-patches@gnu.org; Tue, 19 May 2020 03:24:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#41350] [PATCH v2 1/3] utils: Move 'reset-timestamps' out of database. References: <87mu66q3rt.fsf@gnu.org> In-Reply-To: <87mu66q3rt.fsf@gnu.org> Resent-From: "Jan (janneke) Nieuwenhuizen" Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 19 May 2020 07:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41350 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 41350@debbugs.gnu.org, Mathieu Othacehe Received: via spool by 41350-submit@debbugs.gnu.org id=B41350.158987300814816 (code B ref 41350); Tue, 19 May 2020 07:24:02 +0000 Received: (at 41350) by debbugs.gnu.org; 19 May 2020 07:23:28 +0000 Received: from localhost ([127.0.0.1]:49038 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jawb1-0003qn-KH for submit@debbugs.gnu.org; Tue, 19 May 2020 03:23:28 -0400 Received: from eggs.gnu.org ([209.51.188.92]:36966) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jawal-0003q5-Lg for 41350@debbugs.gnu.org; Tue, 19 May 2020 03:23:12 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:45779) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jawaf-0000a8-OD; Tue, 19 May 2020 03:23:05 -0400 Received: from [2001:980:1b4f:1:42d2:832d:bb59:862] (port=39336 helo=dundal.fritz.box) by fencepost.gnu.org with esmtpa (Exim 4.82) (envelope-from ) id 1jawad-0002jm-F7; Tue, 19 May 2020 03:23:03 -0400 From: "Jan (janneke) Nieuwenhuizen" Date: Tue, 19 May 2020 09:23:00 +0200 Message-Id: <20200519072302.9202-1-janneke@gnu.org> X-Mailer: git-send-email 2.26.2 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 This supports calling reset-timestamps without loading sqlite3. * guix/store/database.scm (reset-timestamps): Move to... * guix/utils.scm (reset-timestamps): ... here. * gnu/build/vm.scm: Include it. --- gnu/build/vm.scm | 1 + guix/store/database.scm | 41 +++-------------------------------------- guix/utils.scm | 41 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/gnu/build/vm.scm b/gnu/build/vm.scm index 433b5a7e8d..c751e6b0e2 100644 --- a/gnu/build/vm.scm +++ b/gnu/build/vm.scm @@ -26,6 +26,7 @@ #:use-module (guix build utils) #:use-module (guix build store-copy) #:use-module (guix build syscalls) + #:use-module ((guix utils) #:select (reset-timestamps)) #:use-module (guix store database) #:use-module (gnu build bootloader) #:use-module (gnu build linux-boot) diff --git a/guix/store/database.scm b/guix/store/database.scm index ef52036ede..b8fe313c3d 100644 --- a/guix/store/database.scm +++ b/guix/store/database.scm @@ -24,9 +24,8 @@ #:use-module (guix store deduplication) #:use-module (guix base16) #:use-module (guix progress) - #:use-module (guix build syscalls) - #:use-module ((guix build utils) - #:select (mkdir-p executable-file?)) + #:use-module ((guix build utils) #:select (mkdir-p)) + #:use-module ((guix utils) #:select (reset-timestamps)) #:use-module (guix build store-copy) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) @@ -42,8 +41,7 @@ sqlite-register register-path register-items - %epoch - reset-timestamps)) + %epoch)) ;;; Code for working with the store database directly. @@ -227,39 +225,6 @@ Every store item in REFERENCES must already be registered." ;;; ;;; High-level interface. ;;; - -(define* (reset-timestamps file #:key preserve-permissions?) - "Reset the modification time on FILE and on all the files it contains, if -it's a directory. Canonicalize file permissions unless PRESERVE-PERMISSIONS? -is true." - ;; Note: We're resetting to one second after the Epoch like 'guix-daemon' - ;; has always done. - (let loop ((file file) - (type (stat:type (lstat file)))) - (case type - ((directory) - (unless preserve-permissions? - (chmod file #o555)) - (utime file 1 1 0 0) - (let ((parent file)) - (for-each (match-lambda - (("." . _) #f) - ((".." . _) #f) - ((file . properties) - (let ((file (string-append parent "/" file))) - (loop file - (match (assoc-ref properties 'type) - ((or 'unknown #f) - (stat:type (lstat file))) - (type type)))))) - (scandir* parent)))) - ((symlink) - (utime file 1 1 0 0 AT_SYMLINK_NOFOLLOW)) - (else - (unless preserve-permissions? - (chmod file (if (executable-file? file) #o555 #o444))) - (utime file 1 1 0 0))))) - (define* (register-path path #:key (references '()) deriver prefix state-directory (deduplicate? #t) diff --git a/guix/utils.scm b/guix/utils.scm index d7b197fa44..812617dd61 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -35,8 +35,10 @@ #:use-module (rnrs io ports) ;need 'port-position' etc. #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!)) #:use-module (guix memoization) - #:use-module ((guix build utils) #:select (dump-port mkdir-p delete-file-recursively)) - #:use-module ((guix build syscalls) #:select (mkdtemp! fdatasync)) + #:use-module ((guix build utils) + #:select (dump-port mkdir-p delete-file-recursively + executable-file?)) + #:use-module ((guix build syscalls) #:select (mkdtemp! fdatasync scandir*)) #:use-module (ice-9 format) #:use-module (ice-9 regex) #:use-module (ice-9 match) @@ -109,7 +111,8 @@ call-with-decompressed-port compressed-output-port call-with-compressed-output-port - canonical-newline-port)) + canonical-newline-port + reset-timestamps)) ;;; @@ -843,6 +846,38 @@ a location object." fix-hint? (hint condition-fix-hint)) ;string +(define* (reset-timestamps file #:key preserve-permissions?) + "Reset the modification time on FILE and on all the files it contains, if +it's a directory. Canonicalize file permissions unless PRESERVE-PERMISSIONS? +is true." + ;; Note: We're resetting to one second after the Epoch like 'guix-daemon' + ;; has always done. + (let loop ((file file) + (type (stat:type (lstat file)))) + (case type + ((directory) + (unless preserve-permissions? + (chmod file #o555)) + (utime file 1 1 0 0) + (let ((parent file)) + (for-each (match-lambda + (("." . _) #f) + ((".." . _) #f) + ((file . properties) + (let ((file (string-append parent "/" file))) + (loop file + (match (assoc-ref properties 'type) + ((or 'unknown #f) + (stat:type (lstat file))) + (type type)))))) + (scandir* parent)))) + ((symlink) + (utime file 1 1 0 0 AT_SYMLINK_NOFOLLOW)) + (else + (unless preserve-permissions? + (chmod file (if (executable-file? file) #o555 #o444))) + (utime file 1 1 0 0))))) + ;;; Local Variables: ;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1) ;;; End: