Fix: Only remove original file if copying was successful

This commit is contained in:
Mike Farah 2019-08-27 09:21:39 +10:00
parent e0d8cd6bf6
commit fe5842e5f9

9
yq.go
View File

@ -633,11 +633,12 @@ func safelyRenameFile(from string, to string) {
if copyError := copyFileContents(from, to); copyError != nil {
log.Errorf("Failed copying from %v to %v", from, to)
log.Error(copyError.Error())
} else {
removeErr := os.Remove(from)
if removeErr != nil {
log.Errorf("failed removing original file: %s", from)
}
}
removeErr := os.Remove(from)
if removeErr != nil {
log.Errorf("failed removing original file: %s", from)
}
}
}