Skip to content

Commit

Permalink
Fix vfs copy not giving Permission denied when to-path is read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazedProgrammer committed Jan 5, 2019
1 parent 2e38140 commit 4f7008d
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions vfs/init.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,25 @@
(lambda (raw-from-path raw-to-path)
(let* [(from-path (canonicalise raw-from-path))
(to-path (canonicalise raw-to-path))]
(if (not ((.> vfs :exists) from-path))
(error! "No such file")
(if ((.> vfs :exists) to-path)
(error! "File exists")
(letrec [(copy-path (lambda (from to)
(log! (.. "copying " from " to " to))
(if ((.> vfs :isDir) from)
(progn
((.> vfs :makeDir) to)
(do [(path (struct->list ((.> vfs :list) from)))]
(copy-path (.. from "/" path) (.. to "/" path))))
(let* [(read-handle ((.> vfs :open) from "r"))
(write-handle ((.> vfs :open) to "w"))]
((.> write-handle :write) ((.> read-handle :readAll)))
((.> read-handle :close))
((.> write-handle :close))))))]
(copy-path from-path to-path)))))))
(if ((.> vfs :isReadOnly) to-path)
(error! "Permission denied")
(if (not ((.> vfs :exists) from-path))
(error! "No such file")
(if ((.> vfs :exists) to-path)
(error! "File exists")
(letrec [(copy-path (lambda (from to)
(log! (.. "copying " from " to " to))
(if ((.> vfs :isDir) from)
(progn
((.> vfs :makeDir) to)
(do [(path (struct->list ((.> vfs :list) from)))]
(copy-path (.. from "/" path) (.. to "/" path))))
(let* [(read-handle ((.> vfs :open) from "r"))
(write-handle ((.> vfs :open) to "w"))]
((.> write-handle :write) ((.> read-handle :readAll)))
((.> read-handle :close))
((.> write-handle :close))))))]
(copy-path from-path to-path))))))))

(.<! vfs :move (lambda (from-path to-path)
((.> vfs :copy) from-path to-path)
Expand Down

0 comments on commit 4f7008d

Please sign in to comment.