mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-20 20:22:46 +00:00
Implement global.rsync_options (fixes #206)
Signed-off-by: Harry Chen <i@harrychen.xyz>
This commit is contained in:
parent
27e4307375
commit
a64557b86d
@ -58,6 +58,9 @@ type globalConfig struct {
|
|||||||
Retry int `toml:"retry"`
|
Retry int `toml:"retry"`
|
||||||
Timeout int `toml:"timeout"`
|
Timeout int `toml:"timeout"`
|
||||||
|
|
||||||
|
// appended to the options generated by rsync_provider, but before mirror-specific options
|
||||||
|
RsyncOptions []string `toml:"rsync_options"`
|
||||||
|
|
||||||
ExecOnSuccess []string `toml:"exec_on_success"`
|
ExecOnSuccess []string `toml:"exec_on_success"`
|
||||||
ExecOnFailure []string `toml:"exec_on_failure"`
|
ExecOnFailure []string `toml:"exec_on_failure"`
|
||||||
}
|
}
|
||||||
@ -162,7 +165,7 @@ type mirrorConfig struct {
|
|||||||
ExecOnSuccess []string `toml:"exec_on_success"`
|
ExecOnSuccess []string `toml:"exec_on_success"`
|
||||||
ExecOnFailure []string `toml:"exec_on_failure"`
|
ExecOnFailure []string `toml:"exec_on_failure"`
|
||||||
|
|
||||||
// These two options the global options
|
// These two options are appended to the global options
|
||||||
ExecOnSuccessExtra []string `toml:"exec_on_success_extra"`
|
ExecOnSuccessExtra []string `toml:"exec_on_success_extra"`
|
||||||
ExecOnFailureExtra []string `toml:"exec_on_failure_extra"`
|
ExecOnFailureExtra []string `toml:"exec_on_failure_extra"`
|
||||||
|
|
||||||
|
@ -459,4 +459,66 @@ rsync_override_only = true
|
|||||||
So(ok, ShouldBeTrue)
|
So(ok, ShouldBeTrue)
|
||||||
So(p.options, ShouldResemble, []string{"--bar", "baz"})
|
So(p.options, ShouldResemble, []string{"--bar", "baz"})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("rsync global options should work", t, func() {
|
||||||
|
tmpfile, err := os.CreateTemp("", "tunasync")
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
defer os.Remove(tmpfile.Name())
|
||||||
|
|
||||||
|
cfgBlob1 := `
|
||||||
|
[global]
|
||||||
|
name = "test_worker"
|
||||||
|
log_dir = "/var/log/tunasync/{{.Name}}"
|
||||||
|
mirror_dir = "/data/mirrors"
|
||||||
|
concurrent = 10
|
||||||
|
interval = 240
|
||||||
|
retry = 3
|
||||||
|
timeout = 86400
|
||||||
|
rsync_options = ["--global"]
|
||||||
|
|
||||||
|
[manager]
|
||||||
|
api_base = "https://127.0.0.1:5000"
|
||||||
|
token = "some_token"
|
||||||
|
|
||||||
|
[server]
|
||||||
|
hostname = "worker1.example.com"
|
||||||
|
listen_addr = "127.0.0.1"
|
||||||
|
listen_port = 6000
|
||||||
|
ssl_cert = "/etc/tunasync.d/worker1.cert"
|
||||||
|
ssl_key = "/etc/tunasync.d/worker1.key"
|
||||||
|
|
||||||
|
[[mirrors]]
|
||||||
|
name = "foo"
|
||||||
|
provider = "rsync"
|
||||||
|
upstream = "rsync://foo.bar/"
|
||||||
|
interval = 720
|
||||||
|
retry = 2
|
||||||
|
timeout = 3600
|
||||||
|
mirror_dir = "/data/foo"
|
||||||
|
rsync_override = ["--override"]
|
||||||
|
rsync_options = ["--local"]
|
||||||
|
`
|
||||||
|
|
||||||
|
err = os.WriteFile(tmpfile.Name(), []byte(cfgBlob1), 0644)
|
||||||
|
So(err, ShouldEqual, nil)
|
||||||
|
defer tmpfile.Close()
|
||||||
|
|
||||||
|
cfg, err := LoadConfig(tmpfile.Name())
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
|
providers := map[string]mirrorProvider{}
|
||||||
|
for _, m := range cfg.Mirrors {
|
||||||
|
p := newMirrorProvider(m, cfg)
|
||||||
|
providers[p.Name()] = p
|
||||||
|
}
|
||||||
|
|
||||||
|
p, ok := providers["foo"].(*rsyncProvider)
|
||||||
|
So(ok, ShouldBeTrue)
|
||||||
|
So(p.options, ShouldResemble, []string{
|
||||||
|
"--override", // from mirror.rsync_override
|
||||||
|
"--timeout=120", // generated by newRsyncProvider
|
||||||
|
"--global", // from global.rsync_options
|
||||||
|
"--local", // from mirror.rsync_options
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -142,6 +142,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
extraOptions: mirror.RsyncOptions,
|
extraOptions: mirror.RsyncOptions,
|
||||||
rsyncNeverTimeout: mirror.RsyncNoTimeo,
|
rsyncNeverTimeout: mirror.RsyncNoTimeo,
|
||||||
rsyncTimeoutValue: mirror.RsyncTimeout,
|
rsyncTimeoutValue: mirror.RsyncTimeout,
|
||||||
|
globalOptions: cfg.Global.RsyncOptions,
|
||||||
overriddenOptions: mirror.RsyncOverride,
|
overriddenOptions: mirror.RsyncOverride,
|
||||||
useOverrideOnly: mirror.RsyncOverrideOnly,
|
useOverrideOnly: mirror.RsyncOverrideOnly,
|
||||||
rsyncEnv: mirror.Env,
|
rsyncEnv: mirror.Env,
|
||||||
|
@ -14,6 +14,7 @@ type rsyncConfig struct {
|
|||||||
rsyncCmd string
|
rsyncCmd string
|
||||||
upstreamURL, username, password, excludeFile string
|
upstreamURL, username, password, excludeFile string
|
||||||
extraOptions []string
|
extraOptions []string
|
||||||
|
globalOptions []string
|
||||||
overriddenOptions []string
|
overriddenOptions []string
|
||||||
useOverrideOnly bool
|
useOverrideOnly bool
|
||||||
rsyncNeverTimeout bool
|
rsyncNeverTimeout bool
|
||||||
@ -80,6 +81,7 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) {
|
|||||||
if c.overriddenOptions == nil {
|
if c.overriddenOptions == nil {
|
||||||
return nil, errors.New("rsync_override_only is set but no rsync_override provided")
|
return nil, errors.New("rsync_override_only is set but no rsync_override provided")
|
||||||
}
|
}
|
||||||
|
// use overridden options only
|
||||||
} else {
|
} else {
|
||||||
if !c.rsyncNeverTimeout {
|
if !c.rsyncNeverTimeout {
|
||||||
timeo := 120
|
timeo := 120
|
||||||
@ -98,6 +100,10 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) {
|
|||||||
if c.excludeFile != "" {
|
if c.excludeFile != "" {
|
||||||
options = append(options, "--exclude-from", c.excludeFile)
|
options = append(options, "--exclude-from", c.excludeFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.globalOptions != nil {
|
||||||
|
options = append(options, c.globalOptions...)
|
||||||
|
}
|
||||||
if c.extraOptions != nil {
|
if c.extraOptions != nil {
|
||||||
options = append(options, c.extraOptions...)
|
options = append(options, c.extraOptions...)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user