Maxime Devos <maximede...@telenet.be> skribis:

> Ludovic Courtès schreef op wo 01-06-2022 om 18:38 [+0200]:
>> There’s a talk by Lennart Poettering where he explains that, contrary to
>> what one might think, “chown -R $HOME” turns out to be fast enough that
>> systemd-homed can do that unconditionally (off the of my head).
>
> Interesting.

‘%gdm-activation’ has an optimization to recurse only if the top-level
directory has itself the wrong UID:

--8<---------------cut here---------------start------------->8---
(define %gdm-activation
  ;; Ensure /var/lib/gdm is owned by the "gdm" user.  This is normally the
  ;; case but could be wrong if the "gdm" user was created, then removed, and
  ;; then recreated under a different UID/GID: <https://bugs.gnu.org/37423>.
  (with-imported-modules '((guix build utils))
    #~(begin
        (use-modules (guix build utils))

        (let* ((gdm (getpwnam "gdm"))
               (uid (passwd:uid gdm))
               (gid (passwd:gid gdm))
               (st  (stat "/var/lib/gdm" #f)))
          ;; Recurse into /var/lib/gdm only if it has wrong ownership.
          (when (and st
                     (or (not (= uid (stat:uid st)))
                         (not (= gid (stat:gid st)))))
            (for-each (lambda (file)
                        (chown file uid gid))
                      (find-files "/var/lib/gdm"
                                  #:directories? #t)))))))
--8<---------------cut here---------------end--------------->8---

We can use that trick if needed: we’d get only one stat(2) call in the
common case.

Ludo’.

Reply via email to