Subject: bug#52452: PATCH v2 2/4] activation: Add 'lchown-recursive'.

From: Maxime Devos <[email-masked]>
Date: Wed, 22 Dec 2021 19:14:14 +0000

>+(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))

This is racy (compare with mkdir-p/perms for example).
This race can be resolved by using 'openat' & 'chownat' &
'AT_SYMLINK_NOFOLLOW' from
<https://lists.gnu.org/archive/html/guile-devel/2021-11/msg00005.html>.

Greetings,
Maxime.