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

Previous Next

Package: guix-patches;

Reported by: Rutherther <rutherther <at> ditigal.xyz>

Date: Sun, 23 Mar 2025 09:49:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #14 received at 77201 <at> debbugs.gnu.org (full text, mbox):

From: Rutherther <rutherther <at> ditigal.xyz>
To: Ludovic Courtès <ludo <at> chbouib.org>, Ian Eure
 <ian <at> retrospec.tv>
Cc: 77201 <at> debbugs.gnu.org
Subject: Re: [bug#77201] [PATCH] guix: substitute-key-authorization: Fix
 case when acl symlink is broken
Date: Tue, 15 Apr 2025 20:26:19 +0200
Hi Ludo,

Ludovic Courtès <ludo <at> chbouib.org> writes:

> Hello,
>
> Ian Eure <ian <at> retrospec.tv> writes:
>
>>> -        (if (file-exists? acl-file)
>>> +        (if (or (file-exists? acl-file) (symbolic-link? acl-file))
>>
>> Guile semantics are unhelpful here: `file-exists?' returns #f for a
>> broken symlink, but `symbolic-link?' raises an exception if given a
>> nonexistent path.
>
> I would go back to the fundamentals:
>
>   (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
          ('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"))))
```
I will probably also make this into a reusable function in guix utils
build, but I have been thinking about a good name and couldn't come up with
one for a week! Programmers problems, I guess.

WDYT

Thanks,
Rutherther




This bug report was last modified 18 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.