summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArun Isaac2025-01-25 01:03:30 +0000
committerArun Isaac2025-01-25 01:03:30 +0000
commit46252b0457bfccc6394c3c521f48185869f741a9 (patch)
tree7a349526f42214cdf44b00bfd538517fb329c0f3
parent9ecda56da7cbae510a7eda82bfbd75a7fbfbe14b (diff)
downloadravanan-46252b0457bfccc6394c3c521f48185869f741a9.tar.gz
ravanan-46252b0457bfccc6394c3c521f48185869f741a9.tar.lz
ravanan-46252b0457bfccc6394c3c521f48185869f741a9.zip
workflow: Hard link instead of copying when interning into the store.
* ravanan/workflow.scm (same-filesystem?): New function. (intern-file): Hard link files if on the same filesystem. Else, copy.
-rw-r--r--ravanan/workflow.scm14
1 files changed, 13 insertions, 1 deletions
diff --git a/ravanan/workflow.scm b/ravanan/workflow.scm
index e6e92bf..282e299 100644
--- a/ravanan/workflow.scm
+++ b/ravanan/workflow.scm
@@ -455,6 +455,12 @@ is the class of the workflow."
;; If location is an URI, parse the URI and return the path part.
(uri-path (string->uri location))))
+(define (same-filesystem? path1 path2)
+ "Return @code{#t} if @var{path1} and @var{path2} are on the same filesystem.
+Else, return @code{#f}."
+ (= (stat:dev (stat path1))
+ (stat:dev (stat path2))))
+
(define (intern-file file store)
"Intern @code{File} type object @var{file} into the ravanan @var{store} unless it
is already a store path. Return an updated @code{File} type object with the
@@ -487,7 +493,13 @@ interned path and location."
(format (current-error-port)
"Interning ~a into store as ~a~%"
path interned-path)
- (copy-file path interned-path)))
+ ;; Hard link if on the same filesystem. Else, copy.
+ ((if (same-filesystem? path
+ (expand-file-name %store-files-directory
+ store))
+ link
+ copy-file)
+ path interned-path)))
interned-path))))
(maybe-assoc-set file
(cons "location" (just (string-append "file://" interned-path)))