summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-01-30 21:01:54 -0800
committerKaz Kylheku <kaz@kylheku.com>2020-01-30 21:01:54 -0800
commitd514eb635cd52fcb57aefaa8a4b74ce9a43a26d8 (patch)
treeb56ae8cba90b68d1a90fbbec08361ddb1b0f9ad7
parentdd97f51e8861211ad89727dea8f7be2dbdf7c050 (diff)
downloadtxr-d514eb635cd52fcb57aefaa8a4b74ce9a43a26d8.tar.gz
txr-d514eb635cd52fcb57aefaa8a4b74ce9a43a26d8.tar.bz2
txr-d514eb635cd52fcb57aefaa8a4b74ce9a43a26d8.zip
copy-file: detect directory before opening.
* share/txr/stdlib/copy-file.tl (copy-file): Detect that from-path is a directory before attempting to open it. The issue is that the open will succeed for a directory, and only the subsequent read will fail. By that time we have opened created the target file.
-rwxr-xr-xshare/txr/stdlib/copy-file.tl23
1 files changed, 13 insertions, 10 deletions
diff --git a/share/txr/stdlib/copy-file.tl b/share/txr/stdlib/copy-file.tl
index aceeb2e8..4f3eabb5 100755
--- a/share/txr/stdlib/copy-file.tl
+++ b/share/txr/stdlib/copy-file.tl
@@ -65,19 +65,22 @@
(with-resources ((buf (make-buf copy-size)
(buf-set-length buf 0) (buf-trim buf))
(ist (open-file from-path "b") (close-stream ist))
- (ost (open-file to-path "wb") (close-stream ost)))
+ (ista (fstat ist))
+ (ost (if (path-dir-p ista)
+ (throwf 'path-permission `~s: ~a is a directory`
+ 'copy-file from-path)
+ (open-file to-path "wb"))
+ (close-stream ost)))
(while (eql (len buf) copy-size)
(fill-buf-adjust buf 0 ist)
(put-buf buf 0 ost))
- (when (or preserve-perms preserve-times)
- (let ((st (fstat ist)))
- (when preserve-perms
- (chmod ost st.mode))
- (when preserve-times
- (flush-stream ost)
- (utimes ost
- st.atime (or st.atime-nsec 0)
- st.mtime (or st.mtime-nsec 0)))))
+ (when preserve-perms
+ (chmod ost ista.mode))
+ (when preserve-times
+ (flush-stream ost)
+ (utimes ost
+ ista.atime (or ista.atime-nsec 0)
+ ista.mtime (or ista.mtime-nsec 0)))
nil))
(defun copy-files (paths dest-dir : preserve-perms preserve-times)