Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Mar 25, 2022
1 parent 9b421a8 commit 7ed32f0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Supported storage systems: https://juicefs.com/docs/community/how_to_setup_objec
Usage: "copy symlinks as symlinks",
},
&cli.Int64Flag{
Name: "limits",
Name: "limit",
Usage: "limit the number of objects that will be processed",
Value: -1,
},
Expand Down
2 changes: 1 addition & 1 deletion docs/en/reference/command_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ The order in which `--exclude` and `--include` are set will affect the result. E
`--links, -l`<br />
copy symlinks as symlinks (default: false)

` --limits value`<br />
` --limit value`<br />
limit the number of objects that will be processed (default: -1)

`--manager value`<br />
Expand Down
2 changes: 1 addition & 1 deletion docs/zh_cn/reference/command_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ juicefs sync [command options] SRC DST
`--links, -l`<br />
将符号链接复制为符号链接 (默认: false)

` --limits value`<br />
` --limit value`<br />
限制将要处理的对象的数量 (默认: -1)

`--manager value`<br />
Expand Down
4 changes: 2 additions & 2 deletions pkg/sync/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Config struct {
Exclude []string
Include []string
Links bool
Limits int64
Limit int64
Manager string
Workers []string
BWLimit int
Expand Down Expand Up @@ -65,7 +65,7 @@ func NewConfigFromCli(c *cli.Context) *Config {
Exclude: c.StringSlice("exclude"),
Include: c.StringSlice("include"),
Links: c.Bool("links"),
Limits: c.Int64("limits"),
Limit: c.Int64("limit"),
Workers: c.StringSlice("worker"),
Manager: c.String("manager"),
BWLimit: c.Int("bwlimit"),
Expand Down
12 changes: 6 additions & 6 deletions pkg/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,11 @@ func deleteFromDst(tasks chan<- object.Object, dstobj object.Object, config *Con
logger.Debug("Ignore deleting dst directory ", dstobj.Key())
return false
}
if config.Limits != -1 {
if config.Limits == 0 {
if config.Limit != -1 {
if config.Limit == 0 {
return true
}
config.Limits--
config.Limit--
}
tasks <- &withSize{dstobj, markDeleteDst}
handled.IncrTotal(1)
Expand Down Expand Up @@ -637,11 +637,11 @@ func producer(tasks chan<- object.Object, src, dst object.ObjectStorage, config
logger.Debug("Ignore directory ", obj.Key())
continue
}
if config.Limits != -1 {
if config.Limits == 0 {
if config.Limit != -1 {
if config.Limit == 0 {
return
}
config.Limits--
config.Limit--
}
handled.IncrTotal(1)

Expand Down
12 changes: 6 additions & 6 deletions pkg/sync/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestSync(t *testing.T) {
Perms: true,
Dry: false,
DeleteSrc: false,
Limits: -1,
Limit: -1,
DeleteDst: false,
Exclude: []string{"c*"},
Include: []string{"a[1-9]", "a*"},
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestSyncIncludeAndExclude(t *testing.T) {
DeleteSrc: false,
DeleteDst: false,
Verbose: false,
Limits: -1,
Limit: -1,
Quiet: true,
Exclude: []string{"1"},
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func TestSyncLink(t *testing.T) {
Perms: true,
Links: true,
Quiet: true,
Limits: -1,
Limit: -1,
ForceUpdate: true,
}); err != nil {
t.Fatalf("sync: %s", err)
Expand Down Expand Up @@ -413,7 +413,7 @@ func TestSyncLinkWithOutFollow(t *testing.T) {
Perms: true,
Quiet: true,
ForceUpdate: true,
Limits: -1,
Limit: -1,
}); err != nil {
t.Fatalf("sync: %s", err)
}
Expand Down Expand Up @@ -447,7 +447,7 @@ func TestSingleLink(t *testing.T) {
Perms: true,
Links: true,
Quiet: true,
Limits: -1,
Limit: -1,
ForceUpdate: true,
}); err != nil {
t.Fatalf("sync: %s", err)
Expand Down Expand Up @@ -500,7 +500,7 @@ func TestLimits(t *testing.T) {
Perms: true,
}
setConfig := func(config *Config, subC subConfig) {
config.Limits = subC.limit
config.Limit = subC.limit
config.DeleteDst = subC.deleteDst
}

Expand Down

0 comments on commit 7ed32f0

Please sign in to comment.