MCPcopy Create free account
hub / github.com/dropbox/dbxcli / validateRemoveTargets

Function validateRemoveTargets

cmd/rm.go:126–155  ·  view source on GitHub ↗
(dbx filesClient, args []string, opts removeOptions)

Source from the content-addressed store, hash-verified

124}
125
126func validateRemoveTargets(dbx filesClient, args []string, opts removeOptions) ([]removeTarget, error) {
127 var targets []removeTarget
128
129 // Validate remove paths before executing removal
130 for i := range args {
131 path, err := validatePath(args[i])
132 if err != nil {
133 return nil, err
134 }
135
136 pathMetaData, err := getFileMetadata(dbx, path)
137 if err != nil {
138 return nil, withJSONErrorDetails(err, operationErrorDetails(removeOperation(opts)), pathErrorDetails(path))
139 }
140
141 if _, ok := pathMetaData.(*files.FileMetadata); !ok && !opts.allowNonEmptyFolder() {
142 folderArg := files.NewListFolderArg(path)
143 res, err := dbx.ListFolderContext(currentContext(), folderArg)
144 if err != nil {
145 return nil, withJSONErrorDetails(err, operationErrorDetails(removeOperation(opts)), pathErrorDetails(path))
146 }
147 if len(res.Entries) != 0 {
148 return nil, invalidArgumentsErrorfWithDetails("rm: cannot remove ‘%s’: Directory not empty, use `--force`/`-f` or `--recursive`/`-r` to proceed", mergeJSONErrorDetails(operationErrorDetails(removeOperation(opts)), pathErrorDetails(path)), path)
149 }
150 }
151 targets = append(targets, removeTarget{path: path, metadata: pathMetaData})
152 }
153
154 return targets, nil
155}
156
157func removeTargets(dbx filesClient, targets []removeTarget, opts removeOptions) ([]removeResult, error) {
158 results := make([]removeResult, 0, len(targets))

Callers 1

rmFunction · 0.85

Calls 11

validatePathFunction · 0.85
getFileMetadataFunction · 0.85
withJSONErrorDetailsFunction · 0.85
operationErrorDetailsFunction · 0.85
removeOperationFunction · 0.85
pathErrorDetailsFunction · 0.85
currentContextFunction · 0.85
mergeJSONErrorDetailsFunction · 0.85
allowNonEmptyFolderMethod · 0.80
ListFolderContextMethod · 0.65

Tested by

no test coverage detected