Eliminate duplicate mirrorProvider in Hooks

This commit is contained in:
WANG Ziqin 2019-07-31 16:11:56 +08:00
parent 8408236646
commit 06fce98c00
5 changed files with 27 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -11,13 +11,14 @@ import (
type zfsHook struct {
emptyHook
provider mirrorProvider
zpool string
}
func newZfsHook(provider mirrorProvider, zpool string) *zfsHook {
return &zfsHook{
emptyHook: emptyHook{
provider: provider,
},
zpool: zpool,
}
}
@ -40,12 +41,12 @@ func (z *zfsHook) printHelpMessage() {
func (z *zfsHook) preJob() error {
workingDir := z.provider.WorkingDir()
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()
return err
}
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()
return err
}