diff --git a/remote/remote.go b/remote/remote.go index 14895a31d..1bcbd11e9 100644 --- a/remote/remote.go +++ b/remote/remote.go @@ -163,19 +163,8 @@ func HaveLocalState() (bool, error) { if err != nil { return false, err } - return ExistsFile(path) -} -// ExistsFile is used to check if a given file exists -func ExistsFile(path string) (bool, error) { - _, err := os.Stat(path) - if err == nil { - return true, nil - } - if os.IsNotExist(err) { - return false, nil - } - return false, err + return existsFile(path) } // ValidConfig does a purely logical validation of the remote config @@ -405,7 +394,7 @@ func Persist(r io.Reader) error { backupPath := filepath.Join(cwd, LocalDirectory, BackupHiddenStateFile) // Backup the old file if it exists - if err := CopyFile(statePath, backupPath); err != nil { + if err := copyFile(statePath, backupPath); err != nil { return fmt.Errorf("Failed to backup state file '%s' to '%s': %v", statePath, backupPath, err) } @@ -425,9 +414,9 @@ func Persist(r io.Reader) error { return nil } -// CopyFile is used to copy from a source file if it exists to a destination. +// copyFile is used to copy from a source file if it exists to a destination. // This is used to create a backup of the state file. -func CopyFile(src, dst string) error { +func copyFile(src, dst string) error { srcFH, err := os.Open(src) if err != nil { if os.IsNotExist(err) { @@ -446,3 +435,15 @@ func CopyFile(src, dst string) error { _, err = io.Copy(dstFH, srcFH) return err } + +// existsFile is used to check if a given file exists +func existsFile(path string) (bool, error) { + _, err := os.Stat(path) + if err == nil { + return true, nil + } + if os.IsNotExist(err) { + return false, nil + } + return false, err +}