Commit 011f332a authored by Tommi Virtanen's avatar Tommi Virtanen

Sync flatfs data file and containing directory in Put

Sadly untestable without low-level fault injection or extensive
mocking.
parent 59c69a01
......@@ -101,6 +101,12 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
return err
}
dirF, err := os.Open(dir)
if err != nil {
return err
}
defer dirF.Close()
tmp, err := ioutil.TempFile(dir, "put-")
if err != nil {
return err
......@@ -121,6 +127,9 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
if _, err := tmp.Write(val); err != nil {
return err
}
if err := tmp.Sync(); err != nil {
return err
}
if err := tmp.Close(); err != nil {
return err
}
......@@ -132,6 +141,10 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
}
removed = true
if err := dirF.Sync(); err != nil {
return err
}
return nil
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment