(dbx filesClient, args []string, opts removeOptions)
| 124 | } |
| 125 | |
| 126 | func 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 | |
| 157 | func removeTargets(dbx filesClient, targets []removeTarget, opts removeOptions) ([]removeResult, error) { |
| 158 | results := make([]removeResult, 0, len(targets)) |
no test coverage detected