Skip to content

Commit 4f7008d

Browse files
Fix vfs copy not giving Permission denied when to-path is read-only
1 parent 2e38140 commit 4f7008d

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

vfs/init.lisp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,25 @@
119119
(lambda (raw-from-path raw-to-path)
120120
(let* [(from-path (canonicalise raw-from-path))
121121
(to-path (canonicalise raw-to-path))]
122-
(if (not ((.> vfs :exists) from-path))
123-
(error! "No such file")
124-
(if ((.> vfs :exists) to-path)
125-
(error! "File exists")
126-
(letrec [(copy-path (lambda (from to)
127-
(log! (.. "copying " from " to " to))
128-
(if ((.> vfs :isDir) from)
129-
(progn
130-
((.> vfs :makeDir) to)
131-
(do [(path (struct->list ((.> vfs :list) from)))]
132-
(copy-path (.. from "/" path) (.. to "/" path))))
133-
(let* [(read-handle ((.> vfs :open) from "r"))
134-
(write-handle ((.> vfs :open) to "w"))]
135-
((.> write-handle :write) ((.> read-handle :readAll)))
136-
((.> read-handle :close))
137-
((.> write-handle :close))))))]
138-
(copy-path from-path to-path)))))))
122+
(if ((.> vfs :isReadOnly) to-path)
123+
(error! "Permission denied")
124+
(if (not ((.> vfs :exists) from-path))
125+
(error! "No such file")
126+
(if ((.> vfs :exists) to-path)
127+
(error! "File exists")
128+
(letrec [(copy-path (lambda (from to)
129+
(log! (.. "copying " from " to " to))
130+
(if ((.> vfs :isDir) from)
131+
(progn
132+
((.> vfs :makeDir) to)
133+
(do [(path (struct->list ((.> vfs :list) from)))]
134+
(copy-path (.. from "/" path) (.. to "/" path))))
135+
(let* [(read-handle ((.> vfs :open) from "r"))
136+
(write-handle ((.> vfs :open) to "w"))]
137+
((.> write-handle :write) ((.> read-handle :readAll)))
138+
((.> read-handle :close))
139+
((.> write-handle :close))))))]
140+
(copy-path from-path to-path))))))))
139141

140142
(.<! vfs :move (lambda (from-path to-path)
141143
((.> vfs :copy) from-path to-path)

0 commit comments

Comments
 (0)