unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Brian Cully via Guix-patches via <guix-patches@gnu.org>
To: 63044@debbugs.gnu.org
Cc: Brian Cully <bjc@spork.org>
Subject: [bug#63044] [PATCH 2/4] guix: utils: add `change-file-timestamps-recursively' procedure
Date: Sun, 23 Apr 2023 21:18:57 -0400	[thread overview]
Message-ID: <ae03b02637a1f410c778baf2a8c8e21cb6fc0971.1682299133.git.bjc@spork.org> (raw)
In-Reply-To: <b4e732c441aac57f195b758806e339c3353eb5eb.1682299133.git.bjc@spork.org>

There are some packages which use the zip library in `python-setuptools' which
will error and fail to build if it finds files with timestamps before 1980.

Create a new procedure which will update the atime and mtime fields of a
directory to a date and time specified in UTC.

 * guix/utils.scm (change-file-timestamps-recursively): new procedure
---
 guix/utils.scm | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/guix/utils.scm b/guix/utils.scm
index b9657df292..a6de6a82fb 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -17,6 +17,7 @@
 ;;; Copyright © 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
 ;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
 ;;; Copyright © 2023 Philip McGrath <philip@philipmcgrath.com>
+;;; Copyright © 2023 Brian Cully <bjc@spork.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -42,6 +43,7 @@ (define-module (guix utils)
   #:use-module (rnrs io ports)                    ;need 'port-position' etc.
   #:use-module ((rnrs bytevectors) #:select (bytevector-u8-set!))
   #:use-module (guix memoization)
+  #:use-module (guix modules)
   #:use-module ((guix build utils)
                 #:select (dump-port mkdir-p delete-file-recursively
                           call-with-temporary-output-file %xz-parallel-args))
@@ -49,6 +51,7 @@ (define-module (guix utils)
   #:use-module ((guix combinators) #:select (fold2))
   #:use-module (guix diagnostics)           ;<location>, &error-location, etc.
   #:use-module (ice-9 format)
+  #:use-module (ice-9 ftw)
   #:use-module ((ice-9 iconv) #:prefix iconv:)
   #:use-module (ice-9 match)
   #:use-module (ice-9 regex)
@@ -134,6 +137,8 @@ (define-module (guix utils)
             config-directory
             cache-directory
 
+            change-file-timestamps-recursively
+
             readlink*
             go-to-location
             edit-expression
@@ -156,6 +161,30 @@ (define-module (guix utils)
 ;;; Environment variables.
 ;;;
 
+(define (change-file-timestamps-recursively location time)
+  "Recursively Change the atime and mtime of all files in LOCATION to TIME.
+
+TIME is specified in ISO 8601 format (YYYY-mm-dd HH:MM:SS) in UTC."
+
+  (define tm (strptime "%F %H:%M:%S %z" (string-append time " +0000")))
+  (define epoch-seconds (string->number (strftime "%s" (car tm))))
+
+  (let loop ((prefix
+              (substring location
+                         0 (+ 1 (string-rindex location (cut eq? #\/ <>)))))
+             (node (file-system-tree location)))
+    (match node
+      ((name stat) ; flat file
+       (when (not (eq? (stat:type stat) 'symlink))
+         (utime (string-append prefix name) epoch-seconds epoch-seconds)))
+      ((name stat children ...) ; directory
+       (utime (string-append prefix name) epoch-seconds epoch-seconds)
+       (for-each (lambda (child)
+                   (loop (string-append prefix name
+                                        file-name-separator-string)
+                         child))
+                 children)))))
+
 (define (call-with-environment-variables variables thunk)
   "Call THUNK with the environment VARIABLES set."
   (let ((environment (environ)))
-- 
2.39.2





  reply	other threads:[~2023-04-24  1:20 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24  0:14 [bug#63044] [PATCH core-updates] Fix criu and sssd Brian Cully via Guix-patches via
2023-04-24  1:18 ` [bug#63044] [PATCH 1/4] gnu: criu: Use gexps Brian Cully via Guix-patches via
2023-04-24  1:18   ` Brian Cully via Guix-patches via [this message]
2023-04-24  1:18   ` [bug#63044] [PATCH 3/4] gnu: sssd: Change timestamps to 1-Jan-1980 before compressing Brian Cully via Guix-patches via
2023-04-24  1:18   ` [bug#63044] [PATCH 4/4] gnu: criu: " Brian Cully via Guix-patches via
2023-04-24 15:49 ` [bug#63044] [PATCH core-updates] Fix criu and sssd Brian Cully via Guix-patches via
2023-04-30 20:39   ` [bug#63044] [PATCH] gnu: python-setuptools: Disable date checking in bdist_egg.py Ludovic Courtès
2023-05-01  6:32     ` Lars-Dominik Braun
2023-05-01 17:36       ` Brian Cully via Guix-patches via
2023-05-03 20:05         ` Ludovic Courtès
2023-05-03 22:05           ` Brian Cully via Guix-patches via
2023-05-04  0:37             ` Brian Cully via Guix-patches via
2023-05-10 15:18               ` Ludovic Courtès
2023-05-12 22:37                 ` Brian Cully via Guix-patches via
2023-05-13  7:11               ` Lars-Dominik Braun
2023-05-02  0:32   ` jgart via Guix-patches via
2023-04-25 14:35 ` [bug#63044] [PATCH v2] gnu: python: " Brian Cully via Guix-patches via
2023-04-28 13:59   ` [bug#63044] [PATCH core-updates] Fix criu and sssd Brian Cully via Guix-patches via
2023-04-28 14:01 ` [bug#63044] [PATCH v3] gnu: python-setuptools: Disable date checking in bdist_egg.py Brian Cully via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ae03b02637a1f410c778baf2a8c8e21cb6fc0971.1682299133.git.bjc@spork.org \
    --to=guix-patches@gnu.org \
    --cc=63044@debbugs.gnu.org \
    --cc=bjc@spork.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).