Skip to content

Commit 9965401

Browse files
committed
webdav: add size to FileSystem.Create()
1 parent 381b8a3 commit 9965401

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

fs_local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (fs LocalFileSystem) ReadDir(ctx context.Context, name string, recursive bo
114114
return l, errFromOS(err)
115115
}
116116

117-
func (fs LocalFileSystem) Create(ctx context.Context, name string, body io.ReadCloser) error {
117+
func (fs LocalFileSystem) Create(ctx context.Context, name string, body io.ReadCloser, size int64) error {
118118
p, err := fs.localPath(name)
119119
if err != nil {
120120
return err

server.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type FileSystem interface {
1717
Open(ctx context.Context, name string) (io.ReadCloser, error)
1818
Stat(ctx context.Context, name string) (*FileInfo, error)
1919
ReadDir(ctx context.Context, name string, recursive bool) ([]FileInfo, error)
20-
Create(ctx context.Context, name string, body io.ReadCloser) error
20+
Create(ctx context.Context, name string, body io.ReadCloser, size int64) error
2121
RemoveAll(ctx context.Context, name string) error
2222
Mkdir(ctx context.Context, name string) error
2323
Copy(ctx context.Context, name, dest string, options *CopyOptions) (created bool, err error)
@@ -45,7 +45,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
4545
// NewHTTPError creates a new error that is associated with an HTTP status code
4646
// and optionally an error that lead to it. Backends can use this functions to
4747
// return errors that convey some semantics (e.g. 404 not found, 403 access
48-
// denied, etc) while also providing an (optional) arbitrary error context
48+
// denied, etc.) while also providing an (optional) arbitrary error context
4949
// (intended for humans).
5050
func NewHTTPError(statusCode int, cause error) error {
5151
return &internal.HTTPError{Code: statusCode, Err: cause}
@@ -194,7 +194,12 @@ func (b *backend) PropPatch(r *http.Request, update *internal.PropertyUpdate) (*
194194
}
195195

196196
func (b *backend) Put(w http.ResponseWriter, r *http.Request) error {
197-
err := b.FileSystem.Create(r.Context(), r.URL.Path, r.Body)
197+
contentLength := r.Header.Get("Content-Length")
198+
size, err := strconv.ParseInt(contentLength, 10, 64)
199+
if err != nil {
200+
return err
201+
}
202+
err = b.FileSystem.Create(r.Context(), r.URL.Path, r.Body, size)
198203
if err != nil {
199204
return err
200205
}

0 commit comments

Comments
 (0)