* fix(server/webdav) make sure Mtime >= Ctime * fix(server/webdav) avoid variable 'stream' collides with imported package name
This commit is contained in:
parent
32ddab9b01
commit
479fc6d466
@ -8,16 +8,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (h *Handler) getModTime(r *http.Request) time.Time {
|
func (h *Handler) getModTime(r *http.Request) time.Time {
|
||||||
return h.getHeaderTime(r, "X-OC-Mtime")
|
return h.getHeaderTime(r, "X-OC-Mtime", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
// owncloud/ nextcloud haven't impl this, but we can add the support since rclone may support this soon
|
// owncloud/ nextcloud haven't impl this, but we can add the support since rclone may support this soon.
|
||||||
|
// try ModTime if CreateTime not found in header
|
||||||
func (h *Handler) getCreateTime(r *http.Request) time.Time {
|
func (h *Handler) getCreateTime(r *http.Request) time.Time {
|
||||||
return h.getHeaderTime(r, "X-OC-Ctime")
|
return h.getHeaderTime(r, "X-OC-Ctime", "X-OC-Mtime")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) getHeaderTime(r *http.Request, header string) time.Time {
|
func (h *Handler) getHeaderTime(r *http.Request, header, alternative string) time.Time {
|
||||||
hVal := r.Header.Get(header)
|
hVal := r.Header.Get(header)
|
||||||
|
// try alternative
|
||||||
|
if hVal == "" && alternative != "" {
|
||||||
|
hVal = r.Header.Get(alternative)
|
||||||
|
}
|
||||||
if hVal != "" {
|
if hVal != "" {
|
||||||
modTimeUnix, err := strconv.ParseInt(hVal, 10, 64)
|
modTimeUnix, err := strconv.ParseInt(hVal, 10, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -331,21 +331,21 @@ func (h *Handler) handlePut(w http.ResponseWriter, r *http.Request) (status int,
|
|||||||
Modified: h.getModTime(r),
|
Modified: h.getModTime(r),
|
||||||
Ctime: h.getCreateTime(r),
|
Ctime: h.getCreateTime(r),
|
||||||
}
|
}
|
||||||
stream := &stream.FileStream{
|
fsStream := &stream.FileStream{
|
||||||
Obj: &obj,
|
Obj: &obj,
|
||||||
Reader: r.Body,
|
Reader: r.Body,
|
||||||
Mimetype: r.Header.Get("Content-Type"),
|
Mimetype: r.Header.Get("Content-Type"),
|
||||||
}
|
}
|
||||||
if stream.Mimetype == "" {
|
if fsStream.Mimetype == "" {
|
||||||
stream.Mimetype = utils.GetMimeType(reqPath)
|
fsStream.Mimetype = utils.GetMimeType(reqPath)
|
||||||
}
|
}
|
||||||
err = fs.PutDirectly(ctx, path.Dir(reqPath), stream)
|
err = fs.PutDirectly(ctx, path.Dir(reqPath), fsStream)
|
||||||
if errs.IsNotFoundError(err) {
|
if errs.IsNotFoundError(err) {
|
||||||
return http.StatusNotFound, err
|
return http.StatusNotFound, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = r.Body.Close()
|
_ = r.Body.Close()
|
||||||
_ = stream.Close()
|
_ = fsStream.Close()
|
||||||
// TODO(rost): Returning 405 Method Not Allowed might not be appropriate.
|
// TODO(rost): Returning 405 Method Not Allowed might not be appropriate.
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return http.StatusMethodNotAllowed, err
|
return http.StatusMethodNotAllowed, err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user