MCPcopy Index your code
hub / github.com/peak/s5cmd / validateRMCommand

Function validateRMCommand

command/rm.go:244–301  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

242}
243
244func validateRMCommand(c *cli.Context) error {
245 if !c.Args().Present() {
246 return fmt.Errorf("expected at least 1 object to remove")
247 }
248
249 // It might be a reasonable request too. Consider that user wants to delete
250 // all-versions of "a" and "b", but want to delete only a single
251 // version of "c" "someversion". User might want to express this as
252 // `s5cmd rm --all-versions a --all-versions b version-id someversion c`
253 // but, current implementation does not take repetitive flags into account,
254 // anyway, this is not supported in the current implementation.
255 if err := checkVersioningFlagCompatibility(c); err != nil {
256 return err
257 }
258
259 if len(c.Args().Slice()) > 1 && c.String("version-id") != "" {
260 return fmt.Errorf("version-id flag can only be used with single source object")
261 }
262
263 srcurls, err := newURLs(c.Bool("raw"), c.String("version-id"), c.Bool("all-versions"), c.Args().Slice()...)
264 if err != nil {
265 return err
266 }
267
268 if err := checkVersioningWithGoogleEndpoint(c); err != nil {
269 return err
270 }
271
272 var (
273 firstBucket string
274 hasRemote, hasLocal bool
275 )
276 for i, srcurl := range srcurls {
277 // we don't operate on S3 prefixes for copy and delete operations.
278 if srcurl.IsBucket() || srcurl.IsPrefix() {
279 return fmt.Errorf("s3 bucket/prefix cannot be used for delete operations (forgot wildcard character?)")
280 }
281
282 if srcurl.IsRemote() {
283 hasRemote = true
284 } else {
285 hasLocal = true
286 }
287
288 if hasLocal && hasRemote {
289 return fmt.Errorf("arguments cannot have both local and remote sources")
290 }
291 if i == 0 {
292 firstBucket = srcurl.Bucket
293 continue
294 }
295 if srcurl.Bucket != firstBucket {
296 return fmt.Errorf("removal of objects with different buckets in a single command is not allowed")
297 }
298 }
299
300 return nil
301}

Callers 2

TestValidateRMCommandFunction · 0.85
NewDeleteCommandFunction · 0.85

Calls 7

newURLsFunction · 0.85
IsBucketMethod · 0.80
IsPrefixMethod · 0.80
IsRemoteMethod · 0.80
StringMethod · 0.45

Tested by 1

TestValidateRMCommandFunction · 0.68