Merge pull request #97 from ziqin/master

Refine: remove outer `provider`s which shadow the embedded `provider`s provided by `emptyHook`
This commit is contained in:
Yuxiang Zhang 2019-08-02 09:27:04 +08:00 committed by GitHub
commit 3872c41607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 34 deletions

View File

@ -41,12 +41,12 @@ Pre-built binary for Linux x86_64 is available at [Github releases](https://gith
PreSyncing Syncing Success PreSyncing Syncing Success
+-----------+ +-----------+ +-------------+ +--------------+ +-----------+ +----------+ +-----------+ +-------------+ +--------------+
| pre-job +--+->| job run +--->| post-exec +-+-->| post-success | | pre-job +--+->| pre-exec +--->| job run +--->| post-exec +-+-->| post-success |
+-----------+ ^ +-----------+ +-------------+ | +--------------+ +-----------+ ^ +----------+ +-----------+ +-------------+ | +--------------+
| | | |
| +-----------------+ | Failed | +-----------------+ | Failed
+------+ post-fail |<---------+ +----------------+ post-fail |<---------------+
+-----------------+ +-----------------+
``` ```

View File

@ -17,7 +17,6 @@ import (
type cgroupHook struct { type cgroupHook struct {
emptyHook emptyHook
provider mirrorProvider
basePath string basePath string
baseGroup string baseGroup string
created bool created bool
@ -36,7 +35,9 @@ func newCgroupHook(p mirrorProvider, basePath, baseGroup, subsystem, memLimit st
subsystem = "cpu" subsystem = "cpu"
} }
return &cgroupHook{ return &cgroupHook{
emptyHook: emptyHook{
provider: p, provider: p,
},
basePath: basePath, basePath: basePath,
baseGroup: baseGroup, baseGroup: baseGroup,
subsystem: subsystem, subsystem: subsystem,

View File

@ -7,7 +7,6 @@ import (
type dockerHook struct { type dockerHook struct {
emptyHook emptyHook
provider mirrorProvider
image string image string
volumes []string volumes []string
options []string options []string
@ -23,7 +22,9 @@ func newDockerHook(p mirrorProvider, gCfg dockerConfig, mCfg mirrorConfig) *dock
options = append(options, mCfg.DockerOptions...) options = append(options, mCfg.DockerOptions...)
return &dockerHook{ return &dockerHook{
emptyHook: emptyHook{
provider: p, provider: p,
},
image: mCfg.DockerImage, image: mCfg.DockerImage,
volumes: volumes, volumes: volumes,
options: options, options: options,

View File

@ -55,7 +55,9 @@ sleep 10
So(err, ShouldBeNil) So(err, ShouldBeNil)
d := &dockerHook{ d := &dockerHook{
emptyHook: emptyHook{
provider: provider, provider: provider,
},
image: "alpine", image: "alpine",
volumes: []string{ volumes: []string{
fmt.Sprintf("%s:%s", cmdScript, "/bin/cmd.sh"), fmt.Sprintf("%s:%s", cmdScript, "/bin/cmd.sh"),

View File

@ -18,7 +18,6 @@ const (
type execPostHook struct { type execPostHook struct {
emptyHook emptyHook
provider mirrorProvider
// exec on success or on failure // exec on success or on failure
execOn uint8 execOn uint8
@ -37,7 +36,9 @@ func newExecPostHook(provider mirrorProvider, execOn uint8, command string) (*ex
} }
return &execPostHook{ return &execPostHook{
emptyHook: emptyHook{
provider: provider, provider: provider,
},
execOn: execOn, execOn: execOn,
command: cmd, command: cmd,
}, nil }, nil

View File

@ -14,12 +14,13 @@ import (
type logLimiter struct { type logLimiter struct {
emptyHook emptyHook
provider mirrorProvider
} }
func newLogLimiter(provider mirrorProvider) *logLimiter { func newLogLimiter(provider mirrorProvider) *logLimiter {
return &logLimiter{ return &logLimiter{
emptyHook: emptyHook{
provider: provider, provider: provider,
},
} }
} }

View File

@ -141,10 +141,10 @@ func newMirrorProvider(mirror mirrorConfig, cfg *Config) mirrorProvider {
retry: mirror.Retry, retry: mirror.Retry,
} }
p, err := newRsyncProvider(rc) p, err := newRsyncProvider(rc)
p.isMaster = isMaster
if err != nil { if err != nil {
panic(err) panic(err)
} }
p.isMaster = isMaster
provider = p provider = p
case provTwoStageRsync: case provTwoStageRsync:
rc := twoStageRsyncConfig{ rc := twoStageRsyncConfig{

View File

@ -11,13 +11,14 @@ import (
type zfsHook struct { type zfsHook struct {
emptyHook emptyHook
provider mirrorProvider
zpool string zpool string
} }
func newZfsHook(provider mirrorProvider, zpool string) *zfsHook { func newZfsHook(provider mirrorProvider, zpool string) *zfsHook {
return &zfsHook{ return &zfsHook{
emptyHook: emptyHook{
provider: provider, provider: provider,
},
zpool: zpool, zpool: zpool,
} }
} }
@ -40,12 +41,12 @@ func (z *zfsHook) printHelpMessage() {
func (z *zfsHook) preJob() error { func (z *zfsHook) preJob() error {
workingDir := z.provider.WorkingDir() workingDir := z.provider.WorkingDir()
if _, err := os.Stat(workingDir); os.IsNotExist(err) { if _, err := os.Stat(workingDir); os.IsNotExist(err) {
logger.Errorf("Directory %s doesn't exist", workingDir); logger.Errorf("Directory %s doesn't exist", workingDir)
z.printHelpMessage() z.printHelpMessage()
return err return err
} }
if err := sh.Command("mountpoint", "-q", workingDir).Run(); err != nil { if err := sh.Command("mountpoint", "-q", workingDir).Run(); err != nil {
logger.Errorf("%s is not a mount point", workingDir); logger.Errorf("%s is not a mount point", workingDir)
z.printHelpMessage() z.printHelpMessage()
return err return err
} }