mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Fix: Only remove original file if copying was successful
This commit is contained in:
parent
e0d8cd6bf6
commit
fe5842e5f9
3
yq.go
3
yq.go
@ -633,13 +633,14 @@ func safelyRenameFile(from string, to string) {
|
|||||||
if copyError := copyFileContents(from, to); copyError != nil {
|
if copyError := copyFileContents(from, to); copyError != nil {
|
||||||
log.Errorf("Failed copying from %v to %v", from, to)
|
log.Errorf("Failed copying from %v to %v", from, to)
|
||||||
log.Error(copyError.Error())
|
log.Error(copyError.Error())
|
||||||
}
|
} else {
|
||||||
removeErr := os.Remove(from)
|
removeErr := os.Remove(from)
|
||||||
if removeErr != nil {
|
if removeErr != nil {
|
||||||
log.Errorf("failed removing original file: %s", from)
|
log.Errorf("failed removing original file: %s", from)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
||||||
func copyFileContents(src, dst string) (err error) {
|
func copyFileContents(src, dst string) (err error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user