Merge pull request #1653 from aaron-prindle/check-err-none

Updated CopyFileLocal to catch all errrors and have better error mess…
pull/1677/head
Aaron Prindle 2017-06-30 14:28:17 -07:00 committed by GitHub
commit a021ab679f
1 changed files with 20 additions and 12 deletions

View File

@ -139,24 +139,32 @@ func (m *MemoryAsset) Read(p []byte) (int, error) {
} }
func CopyFileLocal(f CopyableFile) error { func CopyFileLocal(f CopyableFile) error {
os.MkdirAll(f.GetTargetDir(), os.ModePerm) if err := os.MkdirAll(f.GetTargetDir(), os.ModePerm); err != nil {
return errors.Wrapf(err, "error making dirs for %s", f.GetTargetDir())
}
targetPath := filepath.Join(f.GetTargetDir(), f.GetTargetName()) targetPath := filepath.Join(f.GetTargetDir(), f.GetTargetName())
os.Remove(targetPath) if _, err := os.Stat(targetPath); err == nil {
target, err := os.Create(targetPath) if err := os.Remove(targetPath); err != nil {
defer target.Close() return errors.Wrapf(err, "error removing file %s", targetPath)
}
}
target, err := os.Create(targetPath)
if err != nil {
return errors.Wrapf(err, "error creating file at %s", targetPath)
}
perms, err := strconv.Atoi(f.GetPermissions()) perms, err := strconv.Atoi(f.GetPermissions())
if err != nil { if err != nil {
return errors.Wrap(err, "Error converting permissions to integer") return errors.Wrapf(err, "error converting permissions %s to integer", perms)
} }
target.Chmod(os.FileMode(perms)) if err := target.Chmod(os.FileMode(perms)); err != nil {
if err != nil { return errors.Wrapf(err, "error changing file permissions for %s", targetPath)
return errors.Wrap(err, "Error changing file permissions")
} }
_, err = io.Copy(target, f) if _, err = io.Copy(target, f); err != nil {
if err != nil { return errors.Wrapf(err, `error copying file %s to target location:
return errors.Wrap(err, "Error copying file to target location, do you have the correct permissions?") do you have the correct permissions? The none driver requires sudo for the "start" command`,
targetPath)
} }
return nil return target.Close()
} }