Merge pull request #5933 from subhamkrai/close-file

ceph: closing file which are open for writing
This commit is contained in:
Travis Nielsen authored and GitHub committed 2020-07-30 19:28:39 -06:00
commit 1df67bb603
4 files changed
+17 -1

No files matched your search

+3
View File
@@ -215,6 +215,9 @@ func TerminateFatal(reason error) {
if _, err = file.WriteString(reason.Error()); err != nil {
fmt.Fprintln(os.Stderr, fmt.Errorf("failed to write message to termination log: %+v", err))
}
if err := file.Close(); err != nil {
logger.Errorf("failed to close file. %v", err)
}
}
os.Exit(1)
+5 -1
View File
@@ -271,7 +271,11 @@ func copyFile(src, dest string) error {
if err != nil {
return errors.Wrapf(err, "error copying file from %s to %s", src, dest)
}
return destFile.Sync()
err = destFile.Sync()
if err := destFile.Close(); err != nil {
return err
}
return err
}
// Gets the flex driver info (vendor, driver name) from a given path where the flex driver exists.
+3
View File
@@ -68,6 +68,9 @@ func copyBinary(sourceDir, targetDir, filename string) error {
if _, err := io.Copy(destinationFile, sourceFile); err != nil {
return err
}
if err := destinationFile.Close(); err != nil {
return err
}
// #nosec targetPath requires the permission to execute
return os.Chmod(targetPath, 0700)
}
+6
View File
@@ -173,6 +173,9 @@ func (*CommandExecutor) ExecuteCommandWithOutputFileTimeout(timeout time.Duratio
}
fileOut, err := ioutil.ReadAll(outFile)
if err := outFile.Close(); err != nil {
return "", err
}
return string(fileOut), err
}
@@ -206,6 +209,9 @@ func (*CommandExecutor) ExecuteCommandWithOutputFile(command, outfileArg string,
// read the entire output file and return that to the caller
fileOut, err := ioutil.ReadAll(outFile)
if err := outFile.Close(); err != nil {
return "", err
}
return string(fileOut), err
}