[PATCH] git: Display a hint when CLONE* lacks permission.

  • Open
  • quality assurance status badge
Details
2 participants
  • Tobias Geerinckx-Rice
  • zimoun
Owner
unassigned
Submitted by
Tobias Geerinckx-Rice
Severity
normal
T
T
Tobias Geerinckx-Rice wrote on 21 Dec 2021 01:51
(address . guix-patches@gnu.org)
20211221005102.17638-1-me@tobias.gr
Without this, it's not obvious where users should even start looking:

$ guix pull
Updating channel 'guix' from Git repository at URL...
guix pull: error: mkdir: Permission denied
$

* guix/git.scm (clone*): Print DIRECTORY as a hint on EPERM.

Reported by karrq on #guix.
---
guix/git.scm | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

Toggle diff (33 lines)
diff --git a/guix/git.scm b/guix/git.scm
index dc2ca1be84..1b322be0fe 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -35,6 +35,7 @@ (define-module (guix git)
#:use-module (guix gexp)
#:use-module (guix sets)
#:use-module ((guix diagnostics) #:select (leave warning))
+ #:use-module (guix ui)
#:use-module (guix progress)
#:autoload (guix swh) (swh-download commit-id?)
#:use-module (rnrs bytevectors)
@@ -200,8 +201,16 @@ (define (clone* url directory)
(clone url directory
(make-clone-options
#:fetch-options (make-default-fetch-options))))
- (lambda _
- (false-if-exception (rmdir directory)))))
+ (lambda args
+ (false-if-exception (rmdir directory))
+ ;; Compensate for unixy errors, e.g., ‘error: mkdir: Permission denied’.
+ ;; XXX This displays the hint before the error. After would be nicer.
+ ;; XXX So would a generic mechanism for dealing with such errors.
+ (match args
+ ((system-error _ _ _ EPERM)
+ (display-hint (format #f (G_ "can you create and write to ~a?")
+ directory)))
+ (_ #f)))))
(define (url+commit->name url sha1)
"Return the string \"<REPO-NAME>-<SHA1:7>\" where REPO-NAME is the name of
--
2.34.0
Z
Z
zimoun wrote on 21 Dec 2021 15:42
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)(address . 52691@debbugs.gnu.org)
86y24exbnk.fsf@gmail.com
Hi Tobias,

On mar., 21 déc. 2021 at 01:51, Tobias Geerinckx-Rice <me@tobias.gr> wrote:
Toggle quote (6 lines)
> Without this, it's not obvious where users should even start looking:
>
> $ guix pull
> Updating channel 'guix' from Git repository at URL...
> guix pull: error: mkdir: Permission denied

Instead of hint, I propose this patch which displays:

Toggle snippet (4 lines)
Updating channel 'guix' from Git repository at 'https://git.savannah.gnu.org/git/guix.git'...
guix pull: error: mkdir: Permission non accordée /home/sitour/.cache/guix/checkouts/pjmkglp4t7znuugeurpurzikxq3tnlaywmisyr27shj7apsnalwq

Somehow, the URL is already reported and the patch exposes the hidden
’directory’ variable whatever the error could be.
Toggle diff (19 lines)
diff --git a/guix/git.scm b/guix/git.scm
index dc2ca1be84..e2285f5f55 100644
--- a/guix/git.scm
+++ b/guix/git.scm
@@ -200,8 +200,12 @@ (define (clone* url directory)
(clone url directory
(make-clone-options
#:fetch-options (make-default-fetch-options))))
- (lambda _
- (false-if-exception (rmdir directory)))))
+ (lambda (key subr fmt args . rest)
+ (let ((message (match args
+ ((reason tail ...)
+ (list (string-append reason " " directory))))))
+ (false-if-exception (rmdir directory))
+ (apply throw key subr fmt message rest)))))
(define (url+commit->name url sha1)
"Return the string \"<REPO-NAME>-<SHA1:7>\" where REPO-NAME is the name of
Toggle quote (2 lines)
> + #:use-module (guix ui)

I think that less UI is outside guix/scripts/ and easy maintenance we
have. Ideally, G_ should only be under guix/scripts/.


Last, if my proposal does not fit, from this snippet,

Toggle snippet (12 lines)
+ (lambda args
+ (false-if-exception (rmdir directory))
+ ;; Compensate for unixy errors, e.g., ‘error: mkdir: Permission denied’.
+ ;; XXX This displays the hint before the error. After would be nicer.
+ ;; XXX So would a generic mechanism for dealing with such errors.
+ (match args
+ ((system-error _ _ _ EPERM)
+ (display-hint (format #f (G_ "can you create and write to ~a?")
+ directory)))
+ (_ #f)))))

the ’match’ can be avoided

Toggle snippet (10 lines)
(lambda (key subr message args . rest)
(false-if-exception (rmdir directory))
;; Compensate for unixy errors, e.g., ‘error: mkdir: Permission denied’.
;; XXX This displays the hint before the error. After would be nicer.
;; XXX So would a generic mechanism for dealing with such errors.
(when (= EPERM (car rest))
(display-hint (format #f (G_ "can you create and write to ~a?")
directory))))

Or someting along these lines. :-)


Cheers,
simon
T
T
Tobias Geerinckx-Rice wrote on 21 Dec 2021 15:56
(name . zimoun)(address . zimon.toutoune@gmail.com)(address . 52691@debbugs.gnu.org)
87fsqmf19c.fsf@nckx
Simon,

zimoun ???
Toggle quote (2 lines)
> Instead of hint, I propose this patch which displays:

Perfect! That's what I wanted to write, but couldn't :-)

(I still don't really understand THROW and friends, or what
exactly your snippet does, but the output is exactly what I had in
mind.)

Thanks! LGTM, obviously.

Toggle quote (2 lines)
> the ’match’ can be avoided

True, but I chose it deliberately, and still prefer it over CAR or
equivalent.

Kind regards,

T G-R
-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCYcHs3w0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW1584IA/1V6Kwg/kdmU8+C+MUilOJvtSwPoK3np5bZO32PK
zsn1APsE7caTAYpjfZVWiBcl02FeqecDj9lMCFlLq3p/xs6SBw==
=PM0w
-----END PGP SIGNATURE-----

Z
Z
zimoun wrote on 21 Dec 2021 16:12
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)(address . 52691@debbugs.gnu.org)
CAJ3okZ3mm3Z7o26esFje4GvXoKzvvDuwrpfOhk+Z43cW9LfodA@mail.gmail.com
Hi,

On Tue, 21 Dec 2021 at 16:03, Tobias Geerinckx-Rice <me@tobias.gr> wrote:

Toggle quote (9 lines)
> zimoun ???
> > Instead of hint, I propose this patch which displays:
>
> Perfect! That's what I wanted to write, but couldn't :-)
>
> (I still don't really understand THROW and friends, or what
> exactly your snippet does, but the output is exactly what I had in
> mind.)

Me neither! Especially with new and old way, And the examples in the
manual do not help very well to understand, IMHO. Another story. :-)

Toggle quote (2 lines)
> Thanks! LGTM, obviously.

Feel free to proceed. :-)


Toggle quote (5 lines)
> > the ’match’ can be avoided
>
> True, but I chose it deliberately, and still prefer it over CAR or
> equivalent.

Yes, me too. This 'car' was because I had been lazy. It was about
this pattern:

(lambda args
(match args
((a b c) #t)
(_ #f)

when 'args' is an error. :-)


Cheers,
simon
?