aboutsummaryrefslogtreecommitdiff
path: root/guix/ui.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludovic.courtes@inria.fr>2023-08-11 17:20:06 +0200
committerLudovic Courtès <ludo@gnu.org>2023-08-17 17:33:53 +0200
commit3363ff1867bb02c4aa4955db917ef1d67f2c47e6 (patch)
tree493d236ccf664a6562007f3c973afbca5b61aea4 /guix/ui.scm
parent9896b37ac53e9b0504de55dd5ba4bfa2c241a7ed (diff)
downloadguix-3363ff1867bb02c4aa4955db917ef1d67f2c47e6.tar
guix-3363ff1867bb02c4aa4955db917ef1d67f2c47e6.tar.gz
ui: 'load*' accepts /dev/fd/N files pointing to a pipe.
This allows users to write Bash commands like: guix time-machine -C <(echo %default-channels) -- ... or: guix build -m <(echo '(specifications->manifest (list "guile"))') Previously, on GNU/Linux, they would fail with: error: failed to load '/dev/fd/63': No such file or directory * guix/ui.scm (try-canonicalize-path): New procedure. (load*): Use it. * tests/guix-build.sh: Test 'guix build -m' with a /dev/fd/N file.
Diffstat (limited to 'guix/ui.scm')
-rw-r--r--guix/ui.scm16
1 files changed, 15 insertions, 1 deletions
diff --git a/guix/ui.scm b/guix/ui.scm
index 47a118364a..6f2d4fe245 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -200,6 +200,20 @@ information, or #f if it could not be found."
(parameterize (((@ (system base compile) default-optimization-level) 1))
exp))
+(define (try-canonicalize-path file)
+ "Like 'canonicalize-path', but return FILE as-is if 'canonicalize-path'
+throws.
+
+This is necessary for corner cases where 'canonicalize-path' fails. One
+example is on Linux when a /dev/fd/N file denotes a pipe, represented as a
+symlink to a non-existent file like 'pipe:[1234]', as in this example:
+
+ sh -c 'stat $(readlink -f /dev/fd/1)' | cat"
+ (catch 'system-error
+ (lambda ()
+ (canonicalize-path file))
+ (const file)))
+
(define* (load* file user-module
#:key (on-error 'nothing-special))
"Load the user provided Scheme source code FILE."
@@ -230,7 +244,7 @@ information, or #f if it could not be found."
;; 'primitive-load', so that FILE is compiled, which then allows
;; us to provide better error reporting with source line numbers.
(without-compiler-optimizations
- (load (canonicalize-path file))))
+ (load (try-canonicalize-path file))))
(const #f))))))
(lambda _
;; XXX: Errors are reported from the pre-unwind handler below, but