diff mbox series

[bug#40955,2/5] build: install: Ignore chown exceptions.

Message ID 20200429084756.25072-2-m.othacehe@gmail.com
State Accepted
Headers show
Series Add new image API. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job

Commit Message

Mathieu Othacehe April 29, 2020, 8:47 a.m. UTC
Changing ownership may require root permissions. As image can now be generated
without root permissions (no VM involved), ignore those exceptions.

* gnu/build/install.scm (evaluate-populate-directive): Ignore chown
exceptions.
---
 gnu/build/install.scm | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ludovic Courtès May 2, 2020, 11:09 a.m. UTC | #1
Hey!

Mathieu Othacehe <m.othacehe@gmail.com> skribis:

> Changing ownership may require root permissions. As image can now be generated
> without root permissions (no VM involved), ignore those exceptions.
>
> * gnu/build/install.scm (evaluate-populate-directive): Ignore chown
> exceptions.
> ---
>  gnu/build/install.scm | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/build/install.scm b/gnu/build/install.scm
> index c0d4d44091..0b0d01cf86 100644
> --- a/gnu/build/install.scm
> +++ b/gnu/build/install.scm
> @@ -63,7 +63,9 @@ directory TARGET."
>            (('directory name uid gid)
>             (let ((dir (string-append target name)))
>               (mkdir-p dir)
> -             (chown dir uid gid)))
> +             ;; This will fail if this is not run from a VM, ignore those
> +             ;; errors.
> +             (false-if-exception (chown dir uid gid))))

We still want the directives to be honored though.

How about having a procedure like:

  (define (ensure-ownership file uid gid)
    (catch 'system-error
      (lambda ()
        (chown file uid gid))
      (lambda args
        (if (= EPERM (system-error-errno args))
            (let ((st (lstat file)))
              (or (and (= uid (stat:uid st)) (= gid (stat:gid st)))
                  (apply throw args)))
            (apply throw args)))))

and use that?

Or perhaps that’s still not helpful but we instead need a guarantee
elsewhere that the UID/GID is going to be honored, perhaps by calling:

  (evaluate-populate-directive … #:default-gid 0 #:default-uid 0)

and have it ignore chown when it matches #:default-uid and
#:default-gid.

Thoughts?

Ludo’.
Mathieu Othacehe May 5, 2020, 1:42 p.m. UTC | #2
Hello Ludo,

Thanks for reviewing :)

> Or perhaps that’s still not helpful but we instead need a guarantee
> elsewhere that the UID/GID is going to be honored, perhaps by calling:
>
>   (evaluate-populate-directive … #:default-gid 0 #:default-uid 0)
>
> and have it ignore chown when it matches #:default-uid and
> #:default-gid.

This seems like a good idea. This way, 'chown' is only applied if the
requested uid/gid doesn't match the default one.

Thanks,

Mathieu
diff mbox series

Patch

diff --git a/gnu/build/install.scm b/gnu/build/install.scm
index c0d4d44091..0b0d01cf86 100644
--- a/gnu/build/install.scm
+++ b/gnu/build/install.scm
@@ -63,7 +63,9 @@  directory TARGET."
           (('directory name uid gid)
            (let ((dir (string-append target name)))
              (mkdir-p dir)
-             (chown dir uid gid)))
+             ;; This will fail if this is not run from a VM, ignore those
+             ;; errors.
+             (false-if-exception (chown dir uid gid))))
           (('directory name uid gid mode)
            (loop `(directory ,name ,uid ,gid))
            (chmod (string-append target name) mode))