mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-12 13:48:06 +00:00
copying file permissions from original file when inline merging - Closes #180
This commit is contained in:
parent
7a6689eb40
commit
8d6e3a6a75
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -846,6 +847,7 @@ c:
|
||||
|
||||
func TestMergeCmd_Inplace(t *testing.T) {
|
||||
filename := writeTempYamlFile(readTempYamlFile("examples/data1.yaml"))
|
||||
os.Chmod(filename, os.FileMode(int(0666)))
|
||||
defer removeTempYamlFile(filename)
|
||||
|
||||
cmd := getRootCommand()
|
||||
@ -853,6 +855,7 @@ func TestMergeCmd_Inplace(t *testing.T) {
|
||||
if result.Error != nil {
|
||||
t.Error(result.Error)
|
||||
}
|
||||
info, _ := os.Stat(filename)
|
||||
gotOutput := readTempYamlFile(filename)
|
||||
expectedOutput := `a: simple
|
||||
b:
|
||||
@ -861,4 +864,5 @@ b:
|
||||
c:
|
||||
test: 1`
|
||||
assertResult(t, expectedOutput, strings.Trim(gotOutput, "\n "))
|
||||
assertResult(t, os.FileMode(int(0666)), info.Mode())
|
||||
}
|
||||
|
12
yq.go
12
yq.go
@ -11,10 +11,10 @@ import (
|
||||
"strings"
|
||||
|
||||
errors "github.com/pkg/errors"
|
||||
"gopkg.in/spf13/cobra.v0"
|
||||
|
||||
yaml "gopkg.in/mikefarah/yaml.v2"
|
||||
logging "gopkg.in/op/go-logging.v1"
|
||||
cobra "gopkg.in/spf13/cobra.v0"
|
||||
)
|
||||
|
||||
var trimOutput = true
|
||||
@ -398,7 +398,15 @@ func readAndUpdate(stdOut io.Writer, inputFile string, updateData updateDataFn)
|
||||
var destination io.Writer
|
||||
var destinationName string
|
||||
if writeInplace {
|
||||
var tempFile, err = ioutil.TempFile("", "temp")
|
||||
info, err := os.Stat(inputFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tempFile, err := ioutil.TempFile("", "temp")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = tempFile.Chmod(info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user