Skip to content

Commit f9a6f52

Browse files
committed
Improve error messages even more for copyfile.
1 parent c02c2e3 commit f9a6f52

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/boot/boot.janet

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,16 +4056,18 @@
40564056

40574057
(defn- copyfile
40584058
[from to]
4059-
(def mode (os/stat from :permissions))
4060-
(if-not mode (errorf "file %s does not exist" from))
4061-
(def b (buffer/new 0x10000))
4062-
(with [ffrom (file/open from :rb)]
4063-
(with [fto (file/open to :wb)]
4064-
(forever
4065-
(file/read ffrom 0x10000 b)
4066-
(when (empty? b) (buffer/trim b) (os/chmod to mode) (break))
4067-
(file/write fto b)
4068-
(buffer/clear b)))))
4059+
(if-with [ffrom (file/open from :rb)]
4060+
(if-with [fto (file/open to :wb)]
4061+
(do
4062+
(def perm (os/stat from :permissions))
4063+
(def b (buffer/new 0x10000))
4064+
(forever
4065+
(file/read ffrom 0x10000 b)
4066+
(when (empty? b) (buffer/trim b) (os/chmod to perm) (break))
4067+
(file/write fto b)
4068+
(buffer/clear b)))
4069+
(errorf "destination file %s cannot be opened for writing" to))
4070+
(errorf "source file %s cannot be opened for reading" from)))
40694071

40704072
(defn- copyrf
40714073
[from to]

0 commit comments

Comments
 (0)