GNU bug report logs - #52713
[PATCH v2 2/4] activation: Add 'lchown-recursive'.

Previous Next

Package: guix-patches;

Reported by: Brice Waegeneire <brice <at> waegenei.re>

Date: Tue, 21 Dec 2021 19:37:02 UTC

Severity: normal

Tags: patch

Merged with 52454, 52712, 52714, 52715

Full log


View this message in rfc822 format

From: Brice Waegeneire <brice <at> waegenei.re>
To: 52713 <at> debbugs.gnu.org
Subject: [bug#52713] [PATCH v2 2/4] activation: Add 'lchown-recursive'.
Date: Tue, 21 Dec 2021 20:36:44 +0100
* gnu/build/activation.scm (lchown-recursive): New procedure.
---
 gnu/build/activation.scm | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/gnu/build/activation.scm b/gnu/build/activation.scm
index 9f6126023c..fff2d61b13 100644
--- a/gnu/build/activation.scm
+++ b/gnu/build/activation.scm
@@ -46,7 +46,8 @@ (define-module (gnu build activation)
             activate-firmware
             activate-ptrace-attach
             activate-current-system
-            mkdir-p/perms))
+            mkdir-p/perms
+            lchown-recursive))
 
 ;;; Commentary:
 ;;;
@@ -105,6 +106,23 @@ (define (mkdir-p/perms directory owner bits)
   (chown directory (passwd:uid owner) (passwd:gid owner))
   (chmod directory bits))
 
+(define (lchown-recursive file owner group)
+  "As 'lchown' but recursively, change ownership of FILE to the integer values
+OWNER and GROUP without dereferencing symbolic links it encounter."
+  (nftw file
+        (lambda (filename statinfo flag base level)
+          (catch 'system-error
+            (lambda ()
+              (when (member flag '(regular directory symlink))
+                (lchown filename owner group)))
+            (lambda args
+              (format (current-error-port)
+                      "warning: failed to chown ~s: ~a~%"
+                      filename
+                      (strerror (system-error-errno args)))))
+          #t)
+        'physical))
+
 (define* (copy-account-skeletons home
                                  #:key
                                  (directory %skeleton-directory)
-- 
2.34.0





This bug report was last modified 3 years and 174 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.