aboutsummaryrefslogtreecommitdiff
path: root/guix/scripts
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-04-19 18:49:29 +0200
committerLudovic Courtès <ludo@gnu.org>2015-04-19 23:34:53 +0200
commitee8591990fd38ee2860f0ab659b05052b10f14c6 (patch)
treea6cae89469853393267548e63d6c5bdf82e92c5b /guix/scripts
parent07c0b6e08264f62d0e55ac16be6d313925badfd9 (diff)
downloadgnu-guix-ee8591990fd38ee2860f0ab659b05052b10f14c6.tar
gnu-guix-ee8591990fd38ee2860f0ab659b05052b10f14c6.tar.gz
guix package: Fix 'readlink*' implementation.
* guix/scripts/package.scm (readlink*): Fix to handle symlinks with relative targets. Taken from ld-wrapper2.in.
Diffstat (limited to 'guix/scripts')
-rw-r--r--guix/scripts/package.scm32
1 files changed, 25 insertions, 7 deletions
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index a42452ae70..1e724b4e19 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -730,13 +730,31 @@ doesn't need it."
(define (readlink* file)
"Call 'readlink' until the result is not a symlink."
- (catch 'system-error
- (lambda ()
- (readlink* (readlink file)))
- (lambda args
- (if (= EINVAL (system-error-errno args))
- file
- (apply throw args)))))
+ (define %max-symlink-depth 50)
+
+ (let loop ((file file)
+ (depth 0))
+ (define (absolute target)
+ (if (absolute-file-name? target)
+ target
+ (string-append (dirname file) "/" target)))
+
+ (if (>= depth %max-symlink-depth)
+ file
+ (call-with-values
+ (lambda ()
+ (catch 'system-error
+ (lambda ()
+ (values #t (readlink file)))
+ (lambda args
+ (let ((errno (system-error-errno args)))
+ (if (or (= errno EINVAL))
+ (values #f file)
+ (apply throw args))))))
+ (lambda (success? target)
+ (if success?
+ (loop (absolute target) (+ depth 1))
+ file))))))
;;;