Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add max delete option #699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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