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

Function FsRecursiveMove

server/handles/fsbatch.go:26–148  ·  view source on GitHub ↗

FsRecursiveMove recursively moves files (individual item permission checks skipped for performance).

(c *gin.Context)

Source from the content-addressed store, hash-verified

24
25// FsRecursiveMove recursively moves files (individual item permission checks skipped for performance).
26func FsRecursiveMove(c *gin.Context) {
27 var req RecursiveMoveReq
28 if err := c.ShouldBind(&req); err != nil {
29 common.ErrorResp(c, err, 400)
30 return
31 }
32
33 user := c.Request.Context().Value(conf.UserKey).(*model.User)
34 if !user.CanMove() {
35 common.ErrorResp(c, errs.PermissionDenied, 403)
36 return
37 }
38 srcDir, err := user.JoinPath(req.SrcDir)
39 if err != nil {
40 common.ErrorResp(c, err, 403)
41 return
42 }
43 srcMeta, err := op.GetNearestMeta(srcDir)
44 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
45 common.ErrorResp(c, err, 500, true)
46 return
47 }
48 if !common.CanWrite(user, srcMeta, srcDir) {
49 common.ErrorResp(c, errs.PermissionDenied, 403)
50 return
51 }
52 common.GinAppendValues(c, conf.MetaKey, srcMeta)
53
54 dstDir, err := user.JoinPath(req.DstDir)
55 if err != nil {
56 common.ErrorResp(c, err, 403)
57 return
58 }
59 dstMeta, err := op.GetNearestMeta(dstDir)
60 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
61 common.ErrorResp(c, err, 500, true)
62 return
63 }
64 if !common.CanWrite(user, dstMeta, dstDir) {
65 common.ErrorResp(c, errs.PermissionDenied, 403)
66 return
67 }
68
69 rootFiles, err := fs.List(c.Request.Context(), srcDir, &fs.ListArgs{})
70 if err != nil {
71 common.ErrorResp(c, err, 500)
72 return
73 }
74
75 var existingFileNames []string
76 if req.ConflictPolicy != OVERWRITE {
77 dstFiles, err := fs.List(c.Request.Context(), dstDir, &fs.ListArgs{})
78 if err != nil {
79 common.ErrorResp(c, err, 500)
80 return
81 }
82 existingFileNames = make([]string, 0, len(dstFiles))
83 for _, dstFile := range dstFiles {

Callers

nothing calls this directly

Calls 15

ErrorRespFunction · 0.92
GetNearestMetaFunction · 0.92
CanWriteFunction · 0.92
GinAppendValuesFunction · 0.92
ListFunction · 0.92
NewQueueFunction · 0.92
ErrorStrRespFunction · 0.92
MoveFunction · 0.92
SuccessWithMsgRespFunction · 0.92
PluralizeFunction · 0.92
CanMoveMethod · 0.80
JoinPathMethod · 0.80

Tested by

no test coverage detected