From 8159ce2d12b326aacbed19857eecf6374d74acb0 Mon Sep 17 00:00:00 2001 From: z4yx Date: Mon, 9 Mar 2020 15:27:32 +0800 Subject: [PATCH] support "rsync_options" array in config --- worker/config.go | 15 ++++++++------- worker/provider.go | 28 +++++++++++++++------------- worker/rsync_provider.go | 4 ++++ worker/two_stage_rsync_provider.go | 4 ++++ 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/worker/config.go b/worker/config.go index d33153e..565a11b 100644 --- a/worker/config.go +++ b/worker/config.go @@ -129,13 +129,14 @@ type mirrorConfig struct { ExecOnSuccessExtra []string `toml:"exec_on_success_extra"` ExecOnFailureExtra []string `toml:"exec_on_failure_extra"` - Command string `toml:"command"` - UseIPv6 bool `toml:"use_ipv6"` - UseIPv4 bool `toml:"use_ipv4"` - ExcludeFile string `toml:"exclude_file"` - Username string `toml:"username"` - Password string `toml:"password"` - Stage1Profile string `toml:"stage1_profile"` + Command string `toml:"command"` + UseIPv6 bool `toml:"use_ipv6"` + UseIPv4 bool `toml:"use_ipv4"` + ExcludeFile string `toml:"exclude_file"` + Username string `toml:"username"` + Password string `toml:"password"` + RsyncOptions []string `toml:"rsync_options"` + Stage1Profile string `toml:"stage1_profile"` MemoryLimit string `toml:"memory_limit"` diff --git a/worker/provider.go b/worker/provider.go index 7431ad4..4e3e199 100644 --- a/worker/provider.go +++ b/worker/provider.go @@ -126,19 +126,20 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider { provider = p case provRsync: rc := rsyncConfig{ - name: mirror.Name, - upstreamURL: mirror.Upstream, - rsyncCmd: mirror.Command, - username: mirror.Username, - password: mirror.Password, - excludeFile: mirror.ExcludeFile, - workingDir: mirrorDir, - logDir: logDir, - logFile: filepath.Join(logDir, "latest.log"), - useIPv6: mirror.UseIPv6, - useIPv4: mirror.UseIPv4, - interval: time.Duration(mirror.Interval) * time.Minute, - retry: mirror.Retry, + name: mirror.Name, + upstreamURL: mirror.Upstream, + rsyncCmd: mirror.Command, + username: mirror.Username, + password: mirror.Password, + excludeFile: mirror.ExcludeFile, + extraOptions: mirror.RsyncOptions, + workingDir: mirrorDir, + logDir: logDir, + logFile: filepath.Join(logDir, "latest.log"), + useIPv6: mirror.UseIPv6, + useIPv4: mirror.UseIPv4, + interval: time.Duration(mirror.Interval) * time.Minute, + retry: mirror.Retry, } p, err := newRsyncProvider(rc) if err != nil { @@ -155,6 +156,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider { username: mirror.Username, password: mirror.Password, excludeFile: mirror.ExcludeFile, + extraOptions: mirror.RsyncOptions, workingDir: mirrorDir, logDir: logDir, logFile: filepath.Join(logDir, "latest.log"), diff --git a/worker/rsync_provider.go b/worker/rsync_provider.go index c0ed57f..8905eee 100644 --- a/worker/rsync_provider.go +++ b/worker/rsync_provider.go @@ -13,6 +13,7 @@ type rsyncConfig struct { name string rsyncCmd string upstreamURL, username, password, excludeFile string + extraOptions []string workingDir, logDir, logFile string useIPv6, useIPv4 bool interval time.Duration @@ -65,6 +66,9 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) { if c.excludeFile != "" { options = append(options, "--exclude-from", c.excludeFile) } + if c.extraOptions != nil { + options = append(options, c.extraOptions...) + } provider.options = options provider.ctx.Set(_WorkingDirKey, c.workingDir) diff --git a/worker/two_stage_rsync_provider.go b/worker/two_stage_rsync_provider.go index 991e8c8..aa085e3 100644 --- a/worker/two_stage_rsync_provider.go +++ b/worker/two_stage_rsync_provider.go @@ -15,6 +15,7 @@ type twoStageRsyncConfig struct { rsyncCmd string stage1Profile string upstreamURL, username, password, excludeFile string + extraOptions []string workingDir, logDir, logFile string useIPv6 bool interval time.Duration @@ -116,6 +117,9 @@ func (p *twoStageRsyncProvider) Options(stage int) ([]string, error) { if p.excludeFile != "" { options = append(options, "--exclude-from", p.excludeFile) } + if p.extraOptions != nil { + options = append(options, p.extraOptions...) + } return options, nil }