1
0
mirror of https://github.com/taigrr/yq synced 2025-01-18 04:53:17 -08:00

Added write-inlplace flag

This commit is contained in:
Mike Farah
2020-11-30 16:05:07 +11:00
parent 8de10e550d
commit 9bc66c80b6
6 changed files with 33 additions and 9 deletions

View File

@@ -1,5 +0,0 @@
package yqlib
import "gopkg.in/op/go-logging.v1"
var log = logging.MustGetLogger("yq-lib")

View File

@@ -9,6 +9,8 @@ import (
yaml "gopkg.in/yaml.v3"
)
var log = logging.MustGetLogger("yq-lib")
type OperationType struct {
Type string
NumArgs uint // number of arguments to the op

View File

@@ -41,15 +41,19 @@ func (w *writeInPlaceHandler) CreateTempFile() (*os.File, error) {
}
err = os.Chmod(file.Name(), info.Mode())
log.Debug("writing to tempfile: %v", file.Name())
w.tempFile = file
return file, err
}
func (w *writeInPlaceHandler) FinishWriteInPlace(evaluatedSuccessfully bool) {
log.Debug("Going to write-inplace, evaluatedSuccessfully=%v, target=%v", evaluatedSuccessfully, w.inputFilename)
safelyCloseFile(w.tempFile)
if evaluatedSuccessfully {
log.Debug("moved temp file to target")
safelyRenameFile(w.tempFile.Name(), w.inputFilename)
} else {
log.Debug("removed temp file")
os.Remove(w.tempFile.Name())
}
}