mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Fix: unable to save office file in root directory of WebDAV
This commit is contained in:
@@ -32,17 +32,17 @@ func moveFiles(ctx context.Context, fs *filesystem.FileSystem, src FileInfo, dst
|
||||
folderIDs []uint
|
||||
)
|
||||
if src.IsDir() {
|
||||
fileIDs = []uint{src.(*model.Folder).ID}
|
||||
folderIDs = []uint{src.(*model.Folder).ID}
|
||||
} else {
|
||||
folderIDs = []uint{src.(*model.File).ID}
|
||||
fileIDs = []uint{src.(*model.File).ID}
|
||||
}
|
||||
|
||||
// 判断是否为重命名
|
||||
if src.GetPosition() == path.Dir(dst) {
|
||||
err = fs.Rename(
|
||||
ctx,
|
||||
fileIDs,
|
||||
folderIDs,
|
||||
fileIDs,
|
||||
path.Base(dst),
|
||||
)
|
||||
} else {
|
||||
|
||||
@@ -35,8 +35,11 @@ func (h *Handler) stripPrefix(p string, uid uint) (string, int, error) {
|
||||
if h.Prefix == "" {
|
||||
return p, http.StatusOK, nil
|
||||
}
|
||||
prefix := h.Prefix + strconv.FormatUint(uint64(uid), 10)
|
||||
prefix := h.Prefix
|
||||
if r := strings.TrimPrefix(p, prefix); len(r) < len(p) {
|
||||
if len(r) == 0 {
|
||||
r = "/"
|
||||
}
|
||||
return util.RemoveSlash(r), http.StatusOK, nil
|
||||
}
|
||||
return p, http.StatusNotFound, errPrefixMismatch
|
||||
@@ -164,9 +167,9 @@ func (h *Handler) confirmLocks(r *http.Request, src, dst string, fs *filesystem.
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if u.Host != r.Host {
|
||||
continue
|
||||
}
|
||||
//if u.Host != r.Host {
|
||||
// continue
|
||||
//}
|
||||
lsrc, status, err = h.stripPrefix(u.Path, fs.User.ID)
|
||||
if err != nil {
|
||||
return nil, status, err
|
||||
@@ -381,9 +384,9 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *fil
|
||||
if err != nil {
|
||||
return http.StatusBadRequest, errInvalidDestination
|
||||
}
|
||||
if u.Host != "" && u.Host != r.Host {
|
||||
return http.StatusBadGateway, errInvalidDestination
|
||||
}
|
||||
//if u.Host != "" && u.Host != r.Host {
|
||||
// return http.StatusBadGateway, errInvalidDestination
|
||||
//}
|
||||
|
||||
src, status, err := h.stripPrefix(r.URL.Path, fs.User.ID)
|
||||
if err != nil {
|
||||
@@ -436,7 +439,9 @@ func (h *Handler) handleCopyMove(w http.ResponseWriter, r *http.Request, fs *fil
|
||||
return copyFiles(ctx, fs, target, dst, r.Header.Get("Overwrite") != "F", depth, 0)
|
||||
}
|
||||
|
||||
release, status, err := h.confirmLocks(r, src, dst, fs)
|
||||
// windows下,某些情况下(网盘根目录下)Office保存文件时附带的锁token只包含源文件,
|
||||
// 此处暂时去除了对dst锁的检查
|
||||
release, status, err := h.confirmLocks(r, src, "", fs)
|
||||
if err != nil {
|
||||
return status, err
|
||||
}
|
||||
@@ -575,9 +580,6 @@ func (h *Handler) handleUnlock(w http.ResponseWriter, r *http.Request, fs *files
|
||||
// OK
|
||||
func (h *Handler) handlePropfind(w http.ResponseWriter, r *http.Request, fs *filesystem.FileSystem) (status int, err error) {
|
||||
reqPath, status, err := h.stripPrefix(r.URL.Path, fs.User.ID)
|
||||
if reqPath == "" {
|
||||
reqPath = "/"
|
||||
}
|
||||
if err != nil {
|
||||
return status, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user