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)
| 78 | // |
| 79 | // See section 9.8.5 for when various HTTP status codes apply. |
| 80 | func 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 | // |
no test coverage detected