mirror of
https://github.com/mikefarah/yq.git
synced 2026-09-01 14:14:52 +08:00
Fixed linting
This commit is contained in:
+42
-39
@@ -46,7 +46,10 @@ func EvaluateStream(filename string, reader io.Reader, node *PathTreeNode, print
|
||||
if errorParsing != nil {
|
||||
return errorParsing
|
||||
}
|
||||
printer.PrintResults(matches)
|
||||
err := printer.PrintResults(matches)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
currentIndex = currentIndex + 1
|
||||
}
|
||||
}
|
||||
@@ -61,9 +64,9 @@ func readDocuments(reader io.Reader, filename string) (*list.List, error) {
|
||||
errorReading := decoder.Decode(&dataBucket)
|
||||
|
||||
if errorReading == io.EOF {
|
||||
switch reader.(type) {
|
||||
switch reader := reader.(type) {
|
||||
case *os.File:
|
||||
safelyCloseFile(reader.(*os.File))
|
||||
safelyCloseFile(reader)
|
||||
}
|
||||
return inputList, nil
|
||||
} else if errorReading != nil {
|
||||
@@ -122,49 +125,49 @@ func EvaluateFileStreamsSequence(expression string, filenames []string, printer
|
||||
return err
|
||||
}
|
||||
|
||||
switch reader.(type) {
|
||||
switch reader := reader.(type) {
|
||||
case *os.File:
|
||||
safelyCloseFile(reader.(*os.File))
|
||||
safelyCloseFile(reader)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func safelyRenameFile(from string, to string) {
|
||||
if renameError := os.Rename(from, to); renameError != nil {
|
||||
log.Debugf("Error renaming from %v to %v, attempting to copy contents", from, to)
|
||||
log.Debug(renameError.Error())
|
||||
// can't do this rename when running in docker to a file targeted in a mounted volume,
|
||||
// so gracefully degrade to copying the entire contents.
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// func safelyRenameFile(from string, to string) {
|
||||
// if renameError := os.Rename(from, to); renameError != nil {
|
||||
// log.Debugf("Error renaming from %v to %v, attempting to copy contents", from, to)
|
||||
// log.Debug(renameError.Error())
|
||||
// // can't do this rename when running in docker to a file targeted in a mounted volume,
|
||||
// // so gracefully degrade to copying the entire contents.
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
||||
func copyFileContents(src, dst string) (err error) {
|
||||
in, err := os.Open(src) // nolint gosec
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer safelyCloseFile(in)
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer safelyCloseFile(out)
|
||||
if _, err = io.Copy(out, in); err != nil {
|
||||
return err
|
||||
}
|
||||
return out.Sync()
|
||||
}
|
||||
// // thanks https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file-in-golang
|
||||
// func copyFileContents(src, dst string) (err error) {
|
||||
// in, err := os.Open(src) // nolint gosec
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer safelyCloseFile(in)
|
||||
// out, err := os.Create(dst)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer safelyCloseFile(out)
|
||||
// if _, err = io.Copy(out, in); err != nil {
|
||||
// return err
|
||||
// }
|
||||
// return out.Sync()
|
||||
// }
|
||||
|
||||
func safelyFlush(writer *bufio.Writer) {
|
||||
if err := writer.Flush(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user