1
0
mirror of https://github.com/janet-lang/janet synced 2025-01-05 05:10:26 +00:00

Improve error messages even more for copyfile.

This commit is contained in:
Calvin Rose 2024-09-07 10:02:26 -05:00
parent c02c2e3f02
commit f9a6f52d9c

View File

@ -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]