From 02d3a5a1fb7275a5f313e1c55e6ae1d297bab50c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Fri, 17 Oct 2025 16:24:45 +0200 Subject: [PATCH] publish: Explicitly update the atime for cache expiry. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mounting file systems with ‘noatime’ is common. Thus, avoid relying on the atime. * guix/scripts/publish.scm (render-narinfo/cached): Add ‘utime’ call on cache hit. Use ‘stat’ instead of ‘file-exists?’. (bake-narinfo+nar): Update comment. Change-Id: Id8c68d3b793922fdadca8cbd02b50368b418bb67 --- guix/scripts/publish.scm | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/guix/scripts/publish.scm b/guix/scripts/publish.scm index 7638bcbd0e95fa83df2cf3cccbdeac0e8f742f5a..1143cd29cfdd1c9d240803930e0090fff5a3f12b 100644 --- a/guix/scripts/publish.scm +++ b/guix/scripts/publish.scm @@ -1,7 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2015 David Thompson ;;; Copyright © 2020 by Amar M. Singh -;;; Copyright © 2015-2022, 2024 Ludovic Courtès +;;; Copyright © 2015-2022, 2024-2025 Ludovic Courtès ;;; Copyright © 2020 Maxim Cournoyer ;;; Copyright © 2021 Simon Tournier ;;; Copyright © 2021, 2022 Mathieu Othacehe @@ -551,16 +551,21 @@ requested using POOL." (first compressions))))) (cond ((string-null? item) (not-found request #:ttl negative-ttl)) - ((file-exists? cached) - ;; Narinfo is in cache, send it. - (values `((content-type . (application/x-nix-narinfo)) - ,@(if ttl - `((cache-control (max-age . ,ttl))) - '())) - (lambda (port) - (display (call-with-input-file cached - read-string) - port)))) + ((stat cached #f) + => + (lambda (stat) + ;; Narinfo is in cache: update its atime to reflect usage (in + ;; case the file system is mounted with 'noatime') and send it. + (let ((now ((@ (guile) current-time)))) + (utime cached now (stat:mtime stat) 0 0)) + (values `((content-type . (application/x-nix-narinfo)) + ,@(if ttl + `((cache-control (max-age . ,ttl))) + '())) + (lambda (port) + (display (call-with-input-file cached + read-string) + port))))) ((and (file-exists? item) ;cheaper than the 'valid-path?' RPC (valid-path? store item)) ;; Nothing in cache: bake the narinfo and nar in the background and