Merge pull request #5933 from subhamkrai/close-file
ceph: closing file which are open for writing
This commit is contained in:
4 files changed
+17
-1
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user