Fixes <http://bugs.gnu.org/26949>.
Reported by Pjotr Prins <pjotr.public12@thebird.nl>.
* guix/build/union.scm (file-is-directory?): Return #f when FILE does
not exist or is a dangling symlink.
(file=?): Pass #f as a second argument to 'stat'; return #f when both
ST1 or ST2 is #f.
* tests/profiles.scm (test-equalm): New macro.
("union vs. dangling symlink"): New test.
Fixes the creation of single-package profiles, reported by Ludovic Courtès.
* guix/build/union.scm (union-build): Add new internal procedure
'union-of-directories' that always creates a directory, containing the code
previously used only to merge multiple directories. Call it from the
multiple-directory case in 'union' and from the top-level 'union-build'.
* guix/build/union.scm: Rewrite; only 'file=?' remains unchanged. Remove
'tree-union' and 'delete-duplicate-leaves' exports. Merge inputs in a
breadth-first fashion. Follow symlinks for purposes of making decisions
about the merge.
* tests/union.scm: Remove tests of 'tree-union' and 'delete-duplicate-leaves'.
* guix/build/union.scm (file=?): Return #f if FILE1 and FILE2 are not
regular files. Fixes a bug whereby collisions among directories would
lead to the invocation of 'file=?' and thus 'call-with-input-file' on
directories. Reported by Mark H. Weaver <mhw@netris.org>.
This significantly reduces I/O when building profiles, especially with
lots of package-specific sub-directories (such as 'share/emacs/24.3',
'texmf', etc.)
* guix/build/union.scm (union-build)[file-tree](others-have-it?): New
procedure. Use it in the 'enter?' parameter of 'file-system-fold';
change 'skip' parameter accordingly.
* tests/union.scm ("union-build"): Ensure that 'include' is a symlink
and 'bin' is a directory.
* guix/build/union.scm (union-build): Prepend "." to the result of
`union-tree', to match the expectations of `delete-duplicate-leaves'.
Don't do mkdir when SUBDIR is ".".
* tests/union.scm ("union-build"): Keep duplicates in %BOOTSTRAP-INPUTS.
* guix/build/union.scm (delete-duplicate-leaves): New procedure.
(union-build)[leaf=?, resolve-collision]: New procedures.
Use `delete-duplicate-leaves' on the result of `tree-union'.
* tests/union.scm ("delete-duplicate-leaves, default",
"delete-duplicate-leaves, file names"): New tests.