Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions command/sync.go
Original file line number Diff line number Diff line change
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