From 993dd0d36ba8e67af5c60d73cb1f9d60741f5418 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Fri, 8 May 2020 16:23:55 +0200 Subject: [PATCH] channels: Preserve permissions when patching . * guix/channels.scm (%bug-41028-patch): Record permissions before invoking SUBSTITUTE* and reset afterwards if file permissions differ from the current user. --- guix/channels.scm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/guix/channels.scm b/guix/channels.scm index 0fa036446c..a102d5bc35 100644 --- a/guix/channels.scm +++ b/guix/channels.scm @@ -393,10 +393,21 @@ to '%package-module-path'." (not (string-contains content "(ice-9 threads)")))) (define (add-missing-ice-9-threads-import source) - ;; Add (ice-9 threads) import in the gexp of 'compute-guix-derivation'. - (substitute* (string-append source "/" %self-build-file) - (("^ +\\(use-modules \\(ice-9 match\\)\\)") - (object->string '(use-modules (ice-9 match) (ice-9 threads)))))) + (let* ((self-build-file (string-append source "/" %self-build-file)) + ;; Record permissions so that we can reset it afterwards in case + ;; we run this as the root user (see ). + ;; TODO: Ideally SUBSTITUTE* would preserve permissions itself. + (stat (stat self-build-file)) + (owner (stat:uid stat)) + (group (stat:gid stat))) + + ;; Add (ice-9 threads) import in the gexp of 'compute-guix-derivation'. + (substitute* self-build-file + (("^ +\\(use-modules \\(ice-9 match\\)\\)") + (object->string '(use-modules (ice-9 match) (ice-9 threads))))) + + (unless (and (eq? (getuid) owner) (eq? (getgid) group)) + (chown self-build-file owner group)))) (patch missing-ice-9-threads-import? add-missing-ice-9-threads-import))) -- 2.26.2