Subject: [bug#76143] [PATCH] gnu: Canonicalize paths before comparing.

From: Noé Lopez <[email-masked]>
Date: Sun, 16 Feb 2025 15:15:16 +0100

Ludovic Courtès <[email-masked]> writes:

> Hi,
>
> Noé Lopez <[email-masked]> skribis:
>
>> --- a/gnu/packages.scm
>> +++ b/gnu/packages.scm
>> @@ -167,11 +167,12 @@ (define %patch-path
>>    ;; Define it after '%package-module-path' so that '%load-path' contains user
>>    ;; directories, allowing patches in $GUIX_PACKAGE_PATH to be found.
>>    (make-parameter
>> -   (map (lambda (directory)
>> -          (if (string=? directory %distro-root-directory)
>> -              (string-append directory "/gnu/packages/patches")
>> -              directory))
>> -        %load-path)))
>> +   (let ((root (try-canonicalize-path %distro-root-directory)))
>> +     (map (lambda (directory)
>> +            (if (string=? (try-canonicalize-path directory) root)
>> +                (string-append directory "/gnu/packages/patches")
>> +                directory))
>> +          %load-path))))
>
> I’m not sure what the goal is but please keep in mind that
> ‘canonicalize-path’ is expensive in terms of system calls (especially if
> ‘%load-path’ is long, and we’d pay it for all program startup times),
> and that the comparison here remains brittle (checking the dev/ino
> fields of ‘stat’ would be more accurate).
>
> Thanks,
> Ludo’.

I was not aware that you could do that with stat, I’ve sent a v2 that
uses stat for comparison which works much better.

The problem I faced was that I needed to create environment variables by
hand so that I could load guile code (including guix’s) in a C program
with no external environment (the packagekit daemon).  It would fail
because of not finding patches since I had a trailing slash in my path.

I’ve resolved the issue by removing the slash, but I wanted to fix it
for everyone else trying to use Guix as a library.