mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 08:55:24 +00:00
Add explicit sync to disk for critical file writes (#1686)
For Orbit operations, make an explicit *os.File.Sync() call and check the error, to make sure the writes are fully flushed to disk. Closes #1679 .
This commit is contained in:
parent
1e11f0f669
commit
3c9d7fd4bb
1
changes/issue-1679-sync-file-writes
Normal file
1
changes/issue-1679-sync-file-writes
Normal file
@ -0,0 +1 @@
|
||||
* Orbit: sync critical file writes to disk.
|
@ -60,7 +60,10 @@ func makeConfigIfNotExists(fp string) error {
|
||||
}
|
||||
}
|
||||
|
||||
_, err := secure.OpenFile(fp, os.O_RDONLY|os.O_CREATE, configFilePerms)
|
||||
f, err := secure.OpenFile(fp, os.O_RDONLY|os.O_CREATE, configFilePerms)
|
||||
if err == nil {
|
||||
f.Close()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -137,6 +137,9 @@ func buildNFPM(opt Options, pkger nfpm.Packager) error {
|
||||
if err := pkger.Package(info, out); err != nil {
|
||||
return errors.Wrap(err, "write package")
|
||||
}
|
||||
if err := out.Sync(); err != nil {
|
||||
return errors.Wrap(err, "sync output file")
|
||||
}
|
||||
log.Info().Str("path", filename).Msg("wrote package")
|
||||
|
||||
return nil
|
||||
|
@ -316,9 +316,9 @@ func cpio(srcPath, dstPath string) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "wait gzip")
|
||||
}
|
||||
err = dst.Close()
|
||||
err = dst.Sync()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "close dst")
|
||||
return errors.Wrap(err, "sync dst")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -70,6 +70,9 @@ func copyFile(srcPath, dstPath string, perm os.FileMode) error {
|
||||
if _, err := io.Copy(dst, src); err != nil {
|
||||
return errors.Wrap(err, "copy src to dst")
|
||||
}
|
||||
if err := dst.Sync(); err != nil {
|
||||
return errors.Wrap(err, "sync dst after copy")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -88,7 +88,10 @@ func (s *fileStore) writeData() error {
|
||||
defer f.Close()
|
||||
|
||||
if err := json.NewEncoder(f).Encode(s.metadata); err != nil {
|
||||
return errors.Wrap(err, "read file store")
|
||||
return errors.Wrap(err, "write file store")
|
||||
}
|
||||
if err := f.Sync(); err != nil {
|
||||
return errors.Wrap(err, "sync file store")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
Loading…
Reference in New Issue
Block a user