all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Brice Waegeneire <brice@waegenei.re>
To: 52713@debbugs.gnu.org
Subject: [bug#52713] [PATCH v2 2/4] activation: Add 'lchown-recursive'.
Date: Tue, 21 Dec 2021 20:36:44 +0100	[thread overview]
Message-ID: <20211221193646.16849-2-brice@waegenei.re> (raw)
In-Reply-To: <8735mleoxo.fsf_-_@waegenei.re>

* 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





  parent reply	other threads:[~2021-12-21 19:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-12 18:28 [bug#52454] [PATCH 0/4] Ensure correct ownership of directory trees in services.Hello Guix, Brice Waegeneire
2021-12-12 18:36 ` [bug#52454] [PATCH 1/4] syscalls: Add 'lchown' Brice Waegeneire
2021-12-18 21:34   ` [bug#52454] [PATCH 0/4] Ensure correct ownership of directory trees in services.Hello Guix, Ludovic Courtès
2021-12-21 19:30     ` [bug#52454] [PATCH v2 0/4] Ensure correct ownership of directory trees in services Brice Waegeneire
2021-12-21 19:36       ` [bug#52715] [PATCH v2 1/4] syscalls: Add 'lchown' Brice Waegeneire
2021-12-21 19:36       ` Brice Waegeneire [this message]
2021-12-21 19:36       ` [bug#52714] [PATCH v2 3/4] services: postgresql: Ensure correct ownership of directory trees Brice Waegeneire
2021-12-21 19:36       ` [bug#52712] [PATCH v2 4/4] services: cuirass: " Brice Waegeneire
2021-12-12 18:36 ` [bug#52454] [PATCH 2/4] activation: Add 'lchown-recursive' Brice Waegeneire
2021-12-12 18:36 ` [bug#52454] [PATCH 3/4] services: postgresql: Ensure correct ownership of directory trees Brice Waegeneire
2021-12-12 18:36 ` [bug#52454] [PATCH 4/4] services: cuirass: " Brice Waegeneire

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

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

  git send-email \
    --in-reply-to=20211221193646.16849-2-brice@waegenei.re \
    --to=brice@waegenei.re \
    --cc=52713@debbugs.gnu.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 external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.