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

Function copyFiles

server/webdav/file.go:80–107  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

78//
79// See section 9.8.5 for when various HTTP status codes apply.
80func copyFiles(ctx context.Context, src, dst string, overwrite bool) (status int, err error) {
81 srcDir := path.Dir(src)
82 dstDir := path.Dir(dst)
83 user := ctx.Value(conf.UserKey).(*model.User)
84 if !user.CanCopy() {
85 return http.StatusForbidden, nil
86 }
87 srcMeta, err := op.GetNearestMeta(srcDir)
88 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
89 return http.StatusInternalServerError, err
90 }
91 if !common.CanRead(user, srcMeta, srcDir) {
92 return http.StatusForbidden, nil
93 }
94 dstMeta, err := op.GetNearestMeta(dstDir)
95 if err != nil && !errors.Is(errors.Cause(err), errs.MetaNotFound) {
96 return http.StatusInternalServerError, err
97 }
98 if !common.CanWrite(user, dstMeta, dstDir) {
99 return http.StatusForbidden, nil
100 }
101 _, err = fs.Copy(context.WithValue(ctx, conf.NoTaskKey, struct{}{}), src, dstDir)
102 if err != nil {
103 return http.StatusInternalServerError, err
104 }
105 // TODO if there are no files copy, should return 204
106 return http.StatusCreated, nil
107}
108
109// walkFS traverses filesystem fs starting at name up to depth levels.
110//

Callers 1

handleCopyMoveMethod · 0.85

Calls 5

GetNearestMetaFunction · 0.92
CanReadFunction · 0.92
CanWriteFunction · 0.92
CopyFunction · 0.92
CanCopyMethod · 0.80

Tested by

no test coverage detected