Skip to content

Commit

Permalink
Improve error messages even more for copyfile.
Browse files Browse the repository at this point in the history
  • Loading branch information
bakpakin committed Sep 7, 2024
1 parent c02c2e3 commit f9a6f52
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/boot/boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f9a6f52

Please sign in to comment.