summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2018-09-10 23:37:48 +0200
committerLudovic Courtès <ludo@gnu.org>2018-09-11 00:14:58 +0200
commit2225d56a14a2d8d29374a14eefe90b3cffa79804 (patch)
treea591bd0ef10b0569442a4b4b2d8a516560a78cec /guix
parentcbb0edd1be1f653d253258dfa90c8b45f288fb1b (diff)
downloadgnu-guix-2225d56a14a2d8d29374a14eefe90b3cffa79804.tar
gnu-guix-2225d56a14a2d8d29374a14eefe90b3cffa79804.tar.gz
profiles: Correctly deal with etc/ being a relative symlink.
Fixes <https://bugs.gnu.org/32686>. Reported by Oleg Pykhalov <go.wigust@gmail.com>. * guix/build/profiles.scm (ensure-writable-directory): Add #:symlink. [absolute?]: New procedure. [unsymlink]: Use it to determine how to resolve readlink's result. (build-profile): Pass SYMLINK to 'ensure-writable-directory'. * tests/profiles.scm ("profile-derivation when etc/ is a relative symlink"): New test.
Diffstat (limited to 'guix')
-rw-r--r--guix/build/profiles.scm15
1 files changed, 12 insertions, 3 deletions
diff --git a/guix/build/profiles.scm b/guix/build/profiles.scm
index df785c85a7..0c23cd300e 100644
--- a/guix/build/profiles.scm
+++ b/guix/build/profiles.scm
@@ -94,12 +94,20 @@ definitions for all the SEARCH-PATHS."
(for-each (write-environment-variable-definition port)
(map (abstract-profile output) variables))))))
-(define (ensure-writable-directory directory)
+(define* (ensure-writable-directory directory
+ #:key (symlink symlink))
"Ensure DIRECTORY exists and is writable. If DIRECTORY is currently a
symlink (to a read-only directory in the store), then delete the symlink and
instead make DIRECTORY a \"real\" directory containing symlinks."
+ (define (absolute? file)
+ (string-prefix? "/" file))
+
(define (unsymlink link)
- (let* ((target (readlink link))
+ (let* ((target (match (readlink link)
+ ((? absolute? target)
+ target)
+ ((? string? relative)
+ (string-append (dirname link) "/" relative))))
;; TARGET might itself be a symlink, so append "/" to make sure
;; 'scandir' enters it.
(files (scandir (string-append target "/")
@@ -149,7 +157,8 @@ SEARCH-PATHS."
;; Make sure we can write to 'OUTPUT/etc'. 'union-build' above could have
;; made 'etc' a symlink to a read-only sub-directory in the store so we need
;; to work around that.
- (ensure-writable-directory (string-append output "/etc"))
+ (ensure-writable-directory (string-append output "/etc")
+ #:symlink symlink)
;; Write 'OUTPUT/etc/profile'.
(build-etc/profile output search-paths))