Subject: bug#23723: closed (Re: bug#23723: patch-shebang phase breaks symlinks)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 12 Sep 2016 19:39:02 +0000

Your bug report

#23723: patch-shebang phase breaks symlinks

which was filed against the guix package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
23723: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=23723
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#23723: patch-shebang phase breaks symlinks
From: [email-masked] (Ludovic Courtès)
To: Jelle Licht <[email-masked]>
Cc: [email-masked]
Date: Mon, 12 Sep 2016 21:37:55 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

[email-masked] (Ludovic Courtès) skribis:

> Jelle Licht <[email-masked]> skribis:

[...]

>> Also, seeing as my experience with the stat utility and similarly styled
>> programming libraries was lacking, I decided to play around with the
>> definition of `list-of-files': It actually does include symlinks, as
>> (stat:type (stat "some-symlinked-file")) gives us a plain old 'regular.
>> Looking into this a bit more, it seems that calling `stat' gives the
>> exact same results on both the linked-to-file and the symlink to that
>> file.
>>
>> For the particular problem I ran into to be fixed, it is imperative that
>> `list-of-files' of `patch-shebangs' includes the symlink; it does after
>> all need to be patched. The way this patching currently happens just
>> clobbers symlinks.
>
> My bad, indeed, ‘list-of-files’ should use ‘lstat’ instead of ‘stat’.

This was fixed some time ago in core-updates by commit
c13a9feb5b64fd819eaed38a17da0284bbe2b8d9; closing this bug!

Ludo’.

Subject: patch-shebang phase breaks symlinks
From: Jelle Licht <[email-masked]>
To: [email-masked]
Date: Wed, 08 Jun 2016 01:42:31 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Hi Guix,

It seems that the patch-shebang functionality does not deal gracefully
with symlinks: it just overwrites them!

After struggling somewhat with getting the recently packaged node 6.0.0
to behave, I found out that `patch-shebang' in (guix build
gnu-build-system) does not work properly on symlinks.

To illustrate, in this specific case, there was an executable
script included with the node tarball, namely
`lib/node-modules/npm/bin/npm-cli.js' with an env-based shebang:
`/usr/bin/env node'.

As the `node' executable will only be available after the `install'
phase of the build system, it is not patched before hand. During the
`install' phase, a symlink is created from `bin/npm' to
`lib/node-modules/npm/bin/npm-cli.js' (in the store output directory
this time, of course). Then the `patch-shebangs' phase finds this
symlink and proceeds to patch it. Instead of transparently following the
symlink and patching the `npm-cli.js' script, the `npm' symlink is
overwritten with a shebang-patched copy of `npm-cli.js'.

For node, this is a problem because of how node loads run-time
dependencies; load paths are resolved relative to the actual file, not
the symlink.

- Jelle