Skip to content

Commit

Permalink
Changed ioutil.WriteFile to be able to force a Sync() call
Browse files Browse the repository at this point in the history
iouti.WriteFile function does not call os.File.Sync internally
(golang/go#20599), so the code has
been updated to forced a sync after each file written by an update
  • Loading branch information
mrodm committed Feb 1, 2018
1 parent 0a89acd commit 7883f78
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pouch.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,22 @@ func (p *pouch) resolveFile(fc FileConfig) error {
return err
}

err = ioutil.WriteFile(fc.Path, []byte(content), mode)
file, err := os.OpenFile(fc.Path, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, mode)
if err != nil {
return fmt.Errorf("couldn't open %s file to be written: %s", fc.Path, err)
}
defer file.Close()

bytesWritten, err := file.Write([]byte(content))
if err != nil {
return fmt.Errorf("couldn't write secret in '%s': %s", fc.Path, err)
}

// Ensure file contents have been committed to disk
file.Sync()

log.Printf("Written %d bytes into %s", bytesWritten, fc.Path)

p.addForNotify(fc.Notify...)
return nil
}
Expand Down

0 comments on commit 7883f78

Please sign in to comment.