mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-21 04:42:46 +00:00
add support of env config for rsync provider
This commit is contained in:
parent
fddb793ca1
commit
365f49e6d3
@ -135,6 +135,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
excludeFile: mirror.ExcludeFile,
|
excludeFile: mirror.ExcludeFile,
|
||||||
extraOptions: mirror.RsyncOptions,
|
extraOptions: mirror.RsyncOptions,
|
||||||
overriddenOptions: mirror.RsyncOverride,
|
overriddenOptions: mirror.RsyncOverride,
|
||||||
|
rsyncEnv: mirror.Env,
|
||||||
workingDir: mirrorDir,
|
workingDir: mirrorDir,
|
||||||
logDir: logDir,
|
logDir: logDir,
|
||||||
logFile: filepath.Join(logDir, "latest.log"),
|
logFile: filepath.Join(logDir, "latest.log"),
|
||||||
@ -159,6 +160,7 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
|
|||||||
password: mirror.Password,
|
password: mirror.Password,
|
||||||
excludeFile: mirror.ExcludeFile,
|
excludeFile: mirror.ExcludeFile,
|
||||||
extraOptions: mirror.RsyncOptions,
|
extraOptions: mirror.RsyncOptions,
|
||||||
|
rsyncEnv: mirror.Env,
|
||||||
workingDir: mirrorDir,
|
workingDir: mirrorDir,
|
||||||
logDir: logDir,
|
logDir: logDir,
|
||||||
logFile: filepath.Join(logDir, "latest.log"),
|
logFile: filepath.Join(logDir, "latest.log"),
|
||||||
|
@ -15,6 +15,7 @@ type rsyncConfig struct {
|
|||||||
upstreamURL, username, password, excludeFile string
|
upstreamURL, username, password, excludeFile string
|
||||||
extraOptions []string
|
extraOptions []string
|
||||||
overriddenOptions []string
|
overriddenOptions []string
|
||||||
|
rsyncEnv map[string]string
|
||||||
workingDir, logDir, logFile string
|
workingDir, logDir, logFile string
|
||||||
useIPv6, useIPv4 bool
|
useIPv6, useIPv4 bool
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
@ -50,6 +51,12 @@ func newRsyncProvider(c rsyncConfig) (*rsyncProvider, error) {
|
|||||||
if c.rsyncCmd == "" {
|
if c.rsyncCmd == "" {
|
||||||
provider.rsyncCmd = "rsync"
|
provider.rsyncCmd = "rsync"
|
||||||
}
|
}
|
||||||
|
if c.username != "" {
|
||||||
|
c.rsyncEnv["USER"] = c.username
|
||||||
|
}
|
||||||
|
if c.password != "" {
|
||||||
|
c.rsyncEnv["RSYNC_PASSWORD"] = c.password
|
||||||
|
}
|
||||||
|
|
||||||
options := []string{
|
options := []string{
|
||||||
"-aHvh", "--no-o", "--no-g", "--stats",
|
"-aHvh", "--no-o", "--no-g", "--stats",
|
||||||
@ -116,18 +123,11 @@ func (p *rsyncProvider) Start() error {
|
|||||||
return errors.New("provider is currently running")
|
return errors.New("provider is currently running")
|
||||||
}
|
}
|
||||||
|
|
||||||
env := map[string]string{}
|
|
||||||
if p.username != "" {
|
|
||||||
env["USER"] = p.username
|
|
||||||
}
|
|
||||||
if p.password != "" {
|
|
||||||
env["RSYNC_PASSWORD"] = p.password
|
|
||||||
}
|
|
||||||
command := []string{p.rsyncCmd}
|
command := []string{p.rsyncCmd}
|
||||||
command = append(command, p.options...)
|
command = append(command, p.options...)
|
||||||
command = append(command, p.upstreamURL, p.WorkingDir())
|
command = append(command, p.upstreamURL, p.WorkingDir())
|
||||||
|
|
||||||
p.cmd = newCmdJob(p, command, p.WorkingDir(), env)
|
p.cmd = newCmdJob(p, command, p.WorkingDir(), p.rsyncEnv)
|
||||||
if err := p.prepareLogFile(false); err != nil {
|
if err := p.prepareLogFile(false); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ type twoStageRsyncConfig struct {
|
|||||||
stage1Profile string
|
stage1Profile string
|
||||||
upstreamURL, username, password, excludeFile string
|
upstreamURL, username, password, excludeFile string
|
||||||
extraOptions []string
|
extraOptions []string
|
||||||
|
rsyncEnv map[string]string
|
||||||
workingDir, logDir, logFile string
|
workingDir, logDir, logFile string
|
||||||
useIPv6 bool
|
useIPv6 bool
|
||||||
interval time.Duration
|
interval time.Duration
|
||||||
@ -69,6 +70,12 @@ func newTwoStageRsyncProvider(c twoStageRsyncConfig) (*twoStageRsyncProvider, er
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.username != "" {
|
||||||
|
c.rsyncEnv["USER"] = c.username
|
||||||
|
}
|
||||||
|
if c.password != "" {
|
||||||
|
c.rsyncEnv["RSYNC_PASSWORD"] = c.password
|
||||||
|
}
|
||||||
if c.rsyncCmd == "" {
|
if c.rsyncCmd == "" {
|
||||||
provider.rsyncCmd = "rsync"
|
provider.rsyncCmd = "rsync"
|
||||||
}
|
}
|
||||||
@ -132,14 +139,6 @@ func (p *twoStageRsyncProvider) Run() error {
|
|||||||
return errors.New("provider is currently running")
|
return errors.New("provider is currently running")
|
||||||
}
|
}
|
||||||
|
|
||||||
env := map[string]string{}
|
|
||||||
if p.username != "" {
|
|
||||||
env["USER"] = p.username
|
|
||||||
}
|
|
||||||
if p.password != "" {
|
|
||||||
env["RSYNC_PASSWORD"] = p.password
|
|
||||||
}
|
|
||||||
|
|
||||||
p.dataSize = ""
|
p.dataSize = ""
|
||||||
stages := []int{1, 2}
|
stages := []int{1, 2}
|
||||||
for _, stage := range stages {
|
for _, stage := range stages {
|
||||||
@ -151,7 +150,7 @@ func (p *twoStageRsyncProvider) Run() error {
|
|||||||
command = append(command, options...)
|
command = append(command, options...)
|
||||||
command = append(command, p.upstreamURL, p.WorkingDir())
|
command = append(command, p.upstreamURL, p.WorkingDir())
|
||||||
|
|
||||||
p.cmd = newCmdJob(p, command, p.WorkingDir(), env)
|
p.cmd = newCmdJob(p, command, p.WorkingDir(), p.rsyncEnv)
|
||||||
if err := p.prepareLogFile(stage > 1); err != nil {
|
if err := p.prepareLogFile(stage > 1); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user