about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2025-12-17 17:53:41 +0000
committerArun Isaac2025-12-17 17:53:41 +0000
commitc7fdf56264781116b80d46f2087e0150db8fb423 (patch)
treeedafe7df4ddaafda44e95584876a7e2c681dd75a
parent433650cdf5c74cf4016434bd11d313158bf9792d (diff)
downloadravanan-c7fdf56264781116b80d46f2087e0150db8fb423.tar.gz
ravanan-c7fdf56264781116b80d46f2087e0150db8fb423.tar.lz
ravanan-c7fdf56264781116b80d46f2087e0150db8fb423.zip
store: Do not attempt to predict when hard linking will fail.
Do not attempt to predict the exact conditions when hard linking will
fail. Just try to hard link first, and fall back to copying when it
fails. Predicting the exact conditions is complicated, and may not
port well.
-rw-r--r--ravanan/store.scm16
1 files changed, 4 insertions, 12 deletions
diff --git a/ravanan/store.scm b/ravanan/store.scm
index a52bb50..f96354b 100644
--- a/ravanan/store.scm
+++ b/ravanan/store.scm
@@ -117,20 +117,12 @@ already exists, do nothing."
                                       ".stderr"))
                     store))
 
-(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 (link-or-copy source destination)
   "Hard link @var{source} to @var{destination} if possible. Else, copy it."
-  ;; Hard link if the source file is on the same filesystem as the destination
-  ;; directory. Else, copy.
-  ((if (same-filesystem? source (dirname destination))
-       link
-       copy-file)
-   source destination))
+  ;; Hard linking can sometimes fail (when files are on different filesystems,
+  ;; different mounts, etc.). In such cases, fall back to copying.
+  (or (false-if-exception (link source destination))
+      (copy-file source destination)))
 
 (define (intern-file file store)
   "Intern @code{File} type object @var{file} into the ravanan @var{store} unless it