diff options
| author | Arun Isaac | 2025-11-29 03:45:28 +0000 |
|---|---|---|
| committer | Arun Isaac | 2025-11-29 03:45:28 +0000 |
| commit | af0ea85c8bd345d80d01476d9e6e8b893f1fb407 (patch) | |
| tree | acd380bcea69d12fc47e2ad643128fbd08426be3 | |
| parent | a7ddeff598ad822c57fc6ebcfeb5ad7615d19cfc (diff) | |
| download | ravanan-af0ea85c8bd345d80d01476d9e6e8b893f1fb407.tar.gz ravanan-af0ea85c8bd345d80d01476d9e6e8b893f1fb407.tar.lz ravanan-af0ea85c8bd345d80d01476d9e6e8b893f1fb407.zip | |
store: Spin out link-or-copy function.
| -rw-r--r-- | ravanan/store.scm | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/ravanan/store.scm b/ravanan/store.scm index 5b9f8b8..43f717d 100644 --- a/ravanan/store.scm +++ b/ravanan/store.scm @@ -120,6 +120,15 @@ 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)) + (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 @@ -153,13 +162,7 @@ interned path and location." (log-info "Interning ~a into store as ~a~%" path interned-path) (mkdir (dirname 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))) + (link-or-copy path interned-path))) interned-path)))) (maybe-assoc-set file (cons "location" (just (string-append "file://" interned-path))) |
