From 8abfaf2c5744b12e3e47dd4e1abc92ac44dc2309 Mon Sep 17 00:00:00 2001 From: Mario Domenech Goulart Date: Mon, 14 Jun 2021 19:38:50 +0200 Subject: Handle symlinks first when moving files to cache When moving files from the temporary directory to the cache directory, we must handle symlinks first. If we handle the _target_ before the symlink, the target will be deleted and `copy-file' will break when trying to copy the symlink, as it will be dangling. Signed-off-by: Peter Bex --- henrietta-cache.scm | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/henrietta-cache.scm b/henrietta-cache.scm index 023e16a..ae5c449 100644 --- a/henrietta-cache.scm +++ b/henrietta-cache.scm @@ -13,7 +13,7 @@ (chicken format) (chicken string) (chicken port) (chicken process) (chicken process-context) (chicken pathname) (chicken io) (chicken sort) - (chicken irregex) + (chicken irregex) (chicken file posix) http-client matchable uri-common srfi-1))) (define (usage code) @@ -125,7 +125,13 @@ EOF (begin (copy-file tmp-file cache-file) (delete-file tmp-file) )))) - (directory tmp-dir #t) ) + ;; Here we have to handle symlinks first. If we handle the + ;; _target_ before the symlink, target will be deleted and + ;; `copy-file' will break when trying to copy the symlink, as it + ;; will be dangling. + (sort (directory tmp-dir #t) + (lambda (f _) + (symbolic-link? (make-pathname tmp-dir f))))) (delete-directory tmp-dir #t) ) ;nb: don't like recursive but top level has hidden contents and don't want those (define (download-files-from-list base-uri files cache-dir) -- cgit v1.2.3