Subject: [bug#77201] [PATCH] guix: substitute-key-authorization: Fix case when acl symlink is broken

From: Ludovic Courtès <[email-masked]>
Date: Wed, 16 Apr 2025 16:11:35 +0200

Hi,

Rutherther <[email-masked]> writes:

>>   (match (and=> (false-if-exception (lstat acl-file)) stat:type)
>>     (#f ;file does not exist
>>      …)
>>     ('symlink
>>      …)
>>     (_
>>      …))
>
> This definitely helps, thanks, I am still not that skilled in Scheme, so
> I wouldn't think about false-if-exception, and using match would also be
> hard for me to figure out.
>
> I have this now (untested for now)
> ```
> (match (and=> (false-if-exception (lstat acl-file)) stat:type)
>           (#f #f) ; File doesn't exist

Indentation is off (see above.)  Also (I’m nitpicking!), margin comment
should not be a full sentence, so rather:

  (#f #f)  ;file doesn't exist

>           ('symlink ; Delete symlink pointing to store; backup otherwise.
>            (if (or (store-file-name? (readlink acl-file)) ; Store symlink
>                    (not (file-exists? acl-file))) ; Broken symlink
>                (delete-file acl-file)
>                (rename-file acl-file (string-append acl-file ".bak"))))
>           (_ ; Backup
>            (rename-file acl-file (string-append acl-file ".bak"))))

Should be good!

> I will probably also make this into a reusable function in guix utils
> build,

Maybe not: (guix build utils) is rarely updated because it entails world
rebuilds, which also means that it’s interfaces must be very generic and
bullet-proof.  So I would keep it local for now.

Thanks,
Ludo’.