remote: just limiting the public API
This commit is contained in:
parent
39d2bf4629
commit
3e3b30f147
|
@ -163,19 +163,8 @@ func HaveLocalState() (bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return ExistsFile(path)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExistsFile is used to check if a given file exists
|
return existsFile(path)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidConfig does a purely logical validation of the remote config
|
// 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)
|
backupPath := filepath.Join(cwd, LocalDirectory, BackupHiddenStateFile)
|
||||||
|
|
||||||
// Backup the old file if it exists
|
// 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)
|
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
|
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.
|
// 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)
|
srcFH, err := os.Open(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
|
@ -446,3 +435,15 @@ func CopyFile(src, dst string) error {
|
||||||
_, err = io.Copy(dstFH, srcFH)
|
_, err = io.Copy(dstFH, srcFH)
|
||||||
return err
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue