summaryrefslogtreecommitdiff
path: root/guix/nar.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-04-12 14:35:01 +0200
committerLudovic Courtès <ludo@gnu.org>2013-04-12 14:42:56 +0200
commit8f3114b7a433480c9534903d23d659ce3fb12ffb (patch)
tree3077872a7d508e7faaee70110f963db71cb156ae /guix/nar.scm
parenta2011be5dfaf2b94a1d0e3dfbcf4b512389b4711 (diff)
downloadgnu-guix-8f3114b7a433480c9534903d23d659ce3fb12ffb.tar
gnu-guix-8f3114b7a433480c9534903d23d659ce3fb12ffb.tar.gz
nar: Add support for symlinks.
* guix/nar.scm (write-file): Add case for type `symlink'. (restore-file): Likewise. * tests/nar.scm (random-file-size, make-file-tree, delete-file-tree, with-file-tree, file-tree-equal?, make-random-bytevector, populate-file): New procedures. (%test-dir): New variable. ("write-file + restore-file"): Use `%test-dir' and `file-tree-equal?'. ("write-file + restore-file with symlinks"): New test.
Diffstat (limited to 'guix/nar.scm')
-rw-r--r--guix/nar.scm23
1 files changed, 20 insertions, 3 deletions
diff --git a/guix/nar.scm b/guix/nar.scm
index 9ae76ff2a9..29b57dc989 100644
--- a/guix/nar.scm
+++ b/guix/nar.scm
@@ -161,6 +161,11 @@ sub-directories of FILE as needed."
(dump f)
(write-string ")" p)))
entries)))
+ ((symlink)
+ (write-string "type" p)
+ (write-string "symlink" p)
+ (write-string "target" p)
+ (write-string (readlink f) p))
(else
(raise (condition (&message (message "ENOSYS"))
(&nar-error)))))
@@ -178,14 +183,26 @@ Restore it as FILE."
(file #f))))))
(let restore ((file file))
+ (define (read-eof-marker)
+ (match (read-string port)
+ (")" #t)
+ (x (raise
+ (condition
+ (&message (message "invalid nar end-of-file marker"))
+ (&nar-read-error (port port) (file file) (token x)))))))
+
(match (list (read-string port) (read-string port) (read-string port))
(("(" "type" "regular")
(call-with-output-file file (cut read-contents port <>))
- (match (read-string port)
- (")" #t)
+ (read-eof-marker))
+ (("(" "type" "symlink")
+ (match (list (read-string port) (read-string port))
+ (("target" target)
+ (symlink target file)
+ (read-eof-marker))
(x (raise
(condition
- (&message (message "invalid nar end-of-file marker"))
+ (&message (message "invalid symlink tokens"))
(&nar-read-error (port port) (file file) (token x)))))))
(("(" "type" "directory")
(let ((dir file))