From f9a6f52d9cda179de13ee2407dbe6c8f39c5fc4c Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 7 Sep 2024 10:02:26 -0500 Subject: [PATCH] Improve error messages even more for `copyfile`. --- src/boot/boot.janet | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 08ac5a08..d1aab5d8 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -4056,16 +4056,18 @@ (defn- copyfile [from to] - (def mode (os/stat from :permissions)) - (if-not mode (errorf "file %s does not exist" from)) - (def b (buffer/new 0x10000)) - (with [ffrom (file/open from :rb)] - (with [fto (file/open to :wb)] - (forever - (file/read ffrom 0x10000 b) - (when (empty? b) (buffer/trim b) (os/chmod to mode) (break)) - (file/write fto b) - (buffer/clear b))))) + (if-with [ffrom (file/open from :rb)] + (if-with [fto (file/open to :wb)] + (do + (def perm (os/stat from :permissions)) + (def b (buffer/new 0x10000)) + (forever + (file/read ffrom 0x10000 b) + (when (empty? b) (buffer/trim b) (os/chmod to perm) (break)) + (file/write fto b) + (buffer/clear b))) + (errorf "destination file %s cannot be opened for writing" to)) + (errorf "source file %s cannot be opened for reading" from))) (defn- copyrf [from to]