MCPcopy Create free account
hub / github.com/OpenListTeam/OpenList / moveFiles

Function moveFiles

server/webdav/file.go:35–74  ·  view source on GitHub ↗

moveFiles moves files and/or directories from src to dst. Individual item permission checks are skipped for performance reasons. See section 9.9.4 for when various HTTP status codes apply.

(ctx context.Context, src, dst string, overwrite bool)

Source from the content-addressed store, hash-verified

33//
34// See section 9.9.4 for when various HTTP status codes apply.
35func moveFiles(ctx context.Context, src, dst string, overwrite bool) (status int, err error) {
36 srcDir := path.Dir(src)
37 dstDir := path.Dir(dst)
38 srcName := path.Base(src)
39 dstName := path.Base(dst)
40 user := ctx.Value(conf.UserKey).(*model.User)
41 if srcDir != dstDir && !user.CanMove() {
42 return http.StatusForbidden, nil
43 }
44 if srcName != dstName && !user.CanRename() {
45 return http.StatusForbidden, nil
46 }
47 srcMeta, err := op.GetNearestMeta(srcDir)
48 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
49 return http.StatusInternalServerError, err
50 }
51 dstMeta, err := op.GetNearestMeta(dstDir)
52 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
53 return http.StatusInternalServerError, err
54 }
55 if !common.CanWrite(user, srcMeta, srcDir) || !common.CanWrite(user, dstMeta, dstDir) {
56 return http.StatusForbidden, nil
57 }
58 if srcDir == dstDir {
59 err = fs.Rename(ctx, src, dstName)
60 } else {
61 _, err = fs.Move(context.WithValue(ctx, conf.NoTaskKey, struct{}{}), src, dstDir)
62 if err != nil {
63 return http.StatusInternalServerError, err
64 }
65 if srcName != dstName {
66 err = fs.Rename(ctx, path.Join(dstDir, srcName), dstName)
67 }
68 }
69 if err != nil {
70 return http.StatusInternalServerError, err
71 }
72 // TODO if there are no files copy, should return 204
73 return http.StatusCreated, nil
74}
75
76// copyFiles copies files and/or directories from src to dst.
77// Individual item permission checks are skipped for performance reasons.

Callers 1

handleCopyMoveMethod · 0.85

Calls 6

GetNearestMetaFunction · 0.92
CanWriteFunction · 0.92
RenameFunction · 0.92
MoveFunction · 0.92
CanMoveMethod · 0.80
CanRenameMethod · 0.80

Tested by

no test coverage detected