Skip to content

Commit

Permalink
Add max delete option
Browse files Browse the repository at this point in the history
  • Loading branch information
GRMrGecko committed Feb 7, 2024
1 parent c1c7ee3 commit c511d2f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions command/sync.go
Expand Up @@ -77,6 +77,11 @@ func NewSyncCommandFlags() []cli.Flag {
Name: "delete",
Usage: "delete objects in destination but not in source",
},
&cli.IntFlag{
Name: "max-delete",
Usage: "don't delete more than NUM files",
Value: -1,
},
&cli.BoolFlag{
Name: "size-only",
Usage: "make size of object only criteria to decide whether an object should be synced",
Expand Down Expand Up @@ -129,6 +134,7 @@ type Sync struct {

// flags
delete bool
maxDelete int
sizeOnly bool
exitOnError bool

Expand All @@ -153,6 +159,7 @@ func NewSync(c *cli.Context) Sync {

// flags
delete: c.Bool("delete"),
maxDelete: c.Int("max-delete"),
sizeOnly: c.Bool("size-only"),
exitOnError: c.Bool("exit-on-error"),

Expand Down Expand Up @@ -508,6 +515,10 @@ func (s Sync) planRun(
if len(dstURLs) == 0 {
return
}
if len(dstURLs) >= s.maxDelete && s.maxDelete >= 0 {
fmt.Printf("Not deleting due %d being higher than maximum delete limit\n", len(dstURLs))
return
}

command, err := generateCommand(c, "rm", defaultFlags, dstURLs...)
if err != nil {
Expand Down

0 comments on commit c511d2f

Please sign in to comment.