1
0
Fork 0

- [kami] made an effort to replicate the permissions when uploading a file.

This commit is contained in:
cage 2022-02-13 14:54:16 +01:00
parent f46fb4dc14
commit 560e01e09e
3 changed files with 26 additions and 18 deletions

View File

@ -314,6 +314,11 @@
(define-stat-time atime)
(defun get-stat-mode (file)
(let ((raw (nix:stat-mode (nix:stat file))))
(values raw
(logand raw #o777))))
(defun file-hash (file)
(num:fnv-hash-32 (slurp-file file :convert-to-string nil)))

View File

@ -118,24 +118,26 @@
(lambda (source-path destination-path)
(let* ((*stream* stream)
(*root-fid* root-fid))
(with-open-file (input-stream source-path
:direction :input
:element-type +octect-type+)
(with-cloned-root-fid (*stream* root-fid)
(9p:remove-path *stream* root-fid destination-path))
(with-cloned-root-fid (*stream* root-fid)
(let* ((buffer (misc:make-array-frame +download-buffer+ 0 +octect-type+ t))
(fid (9p:create-path *stream* root-fid destination-path)))
(loop named write-loop
for read-so-far = (read-sequence buffer input-stream)
then (read-sequence buffer input-stream)
for offset = 0 then (+ offset read-so-far)
do
(9p:9p-write *stream* fid offset (subseq buffer 0 read-so-far))
(when (< read-so-far +download-buffer+)
(return-from write-loop t)))
(9p:9p-clunk *stream* fid)
(9p:read-all-pending-messages stream)))))))
(let ((source-permissions (fs:get-stat-mode source-path)))
(with-open-file (input-stream source-path
:direction :input
:element-type +octect-type+)
(with-cloned-root-fid (*stream* root-fid)
(9p:remove-path *stream* root-fid destination-path))
(with-cloned-root-fid (*stream* root-fid)
(let* ((buffer (misc:make-array-frame +download-buffer+ 0 +octect-type+ t))
(fid (9p:create-path *stream* root-fid destination-path)))
(loop named write-loop
for read-so-far = (read-sequence buffer input-stream)
then (read-sequence buffer input-stream)
for offset = 0 then (+ offset read-so-far)
do
(9p:9p-write *stream* fid offset (subseq buffer 0 read-so-far))
(when (< read-so-far +download-buffer+)
(return-from write-loop t)))
(9p:9p-clunk *stream* fid)
(9p:change-mode *stream* *root-fid* destination-path source-permissions)
(9p:read-all-pending-messages stream))))))))
(defun query-path (stream root-fid)
(lambda (path what)

View File

@ -306,6 +306,7 @@
:get-stat-mtime
:get-stat-ctime
:get-stat-atime
:get-stat-mode
:file-outdated-p
:file-exists-p
:directory-exists-p