diff --git a/plugins/docker-options/functions.go b/plugins/docker-options/functions.go index f00fa5546..57b2d38d3 100644 --- a/plugins/docker-options/functions.go +++ b/plugins/docker-options/functions.go @@ -2,6 +2,7 @@ package dockeroptions import ( "fmt" + "io" "os" "path/filepath" "strings" @@ -13,6 +14,39 @@ func getPhaseFilePath(appName string, phase string) string { return filepath.Join(common.AppRoot(appName), "DOCKER_OPTIONS_"+strings.ToUpper(phase)) } +func copyPhaseFile(srcApp string, dstApp string, phase string) error { + srcPath := getPhaseFilePath(srcApp, phase) + if !common.FileExists(srcPath) { + return nil + } + + src, err := os.Open(srcPath) + if err != nil { + return fmt.Errorf("Unable to open docker options phase file %s.%s: %s", srcApp, phase, err.Error()) + } + defer src.Close() + + dstPath := getPhaseFilePath(dstApp, phase) + dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + if err != nil { + return fmt.Errorf("Unable to create docker options phase file %s.%s: %s", dstApp, phase, err.Error()) + } + defer dst.Close() + + if _, err := io.Copy(dst, src); err != nil { + return fmt.Errorf("Unable to copy docker options phase file %s.%s to %s.%s: %s", srcApp, phase, dstApp, phase, err.Error()) + } + + return nil +} + +func removePhaseFile(appName string, phase string) error { + if err := os.Remove(getPhaseFilePath(appName, phase)); err != nil && !os.IsNotExist(err) { + return err + } + return nil +} + func touchPhaseFile(appName string, phase string) error { phaseFilePath := getPhaseFilePath(appName, phase) diff --git a/plugins/docker-options/subcommands.go b/plugins/docker-options/subcommands.go index f68606245..2f72d7077 100644 --- a/plugins/docker-options/subcommands.go +++ b/plugins/docker-options/subcommands.go @@ -3,7 +3,6 @@ package dockeroptions import ( "errors" "fmt" - "os" "github.com/dokku/dokku/plugins/common" ) @@ -96,10 +95,3 @@ func CommandReport(appName string, format string, infoFlag string) error { return ReportSingleApp(appName, format, infoFlag) } - -func removePhaseFile(appName string, phase string) error { - if err := os.Remove(getPhaseFilePath(appName, phase)); err != nil && !os.IsNotExist(err) { - return err - } - return nil -} diff --git a/plugins/docker-options/triggers.go b/plugins/docker-options/triggers.go index 9e63a06fc..e594291f7 100644 --- a/plugins/docker-options/triggers.go +++ b/plugins/docker-options/triggers.go @@ -1,13 +1,5 @@ package dockeroptions -import ( - "fmt" - "io" - "os" - - "github.com/dokku/dokku/plugins/common" -) - // TriggerPostAppCloneSetup copies docker option files from the source app to the cloned app func TriggerPostAppCloneSetup(oldAppName string, newAppName string) error { for _, phase := range availablePhases { @@ -37,29 +29,3 @@ func TriggerPostDelete(appName string) error { } return nil } - -func copyPhaseFile(srcApp string, dstApp string, phase string) error { - srcPath := getPhaseFilePath(srcApp, phase) - if !common.FileExists(srcPath) { - return nil - } - - src, err := os.Open(srcPath) - if err != nil { - return fmt.Errorf("Unable to open docker options phase file %s.%s: %s", srcApp, phase, err.Error()) - } - defer src.Close() - - dstPath := getPhaseFilePath(dstApp, phase) - dst, err := os.OpenFile(dstPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - if err != nil { - return fmt.Errorf("Unable to create docker options phase file %s.%s: %s", dstApp, phase, err.Error()) - } - defer dst.Close() - - if _, err := io.Copy(dst, src); err != nil { - return fmt.Errorf("Unable to copy docker options phase file %s.%s to %s.%s: %s", srcApp, phase, dstApp, phase, err.Error()) - } - - return nil -}