Commit b91b1e9a authored by Tommi Virtanen's avatar Tommi Virtanen

flatfs: Avoid syncing directories in Windows

Used to error out with

    flatfs_test.go:66: Put fail: failed to open dir: fsync: The handle is invalid

It seems Windows does not want syscall.Fsync to be called on directory
handles.
parent 3814a6f4
...@@ -79,12 +79,7 @@ func (fs *Datastore) makePrefixDir(dir string) error { ...@@ -79,12 +79,7 @@ func (fs *Datastore) makePrefixDir(dir string) error {
// it, the creation of the prefix dir itself might not be // it, the creation of the prefix dir itself might not be
// durable yet. Sync the root dir after a successful mkdir of // durable yet. Sync the root dir after a successful mkdir of
// a prefix dir, just to be paranoid. // a prefix dir, just to be paranoid.
f, err := os.Open(fs.path) if err := syncDir(fs.path); err != nil {
if err != nil {
return err
}
defer f.Close()
if err := f.Sync(); err != nil {
return err return err
} }
return nil return nil
...@@ -101,12 +96,6 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error { ...@@ -101,12 +96,6 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
return err return err
} }
dirF, err := os.Open(dir)
if err != nil {
return err
}
defer dirF.Close()
tmp, err := ioutil.TempFile(dir, "put-") tmp, err := ioutil.TempFile(dir, "put-")
if err != nil { if err != nil {
return err return err
...@@ -141,10 +130,9 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error { ...@@ -141,10 +130,9 @@ func (fs *Datastore) Put(key datastore.Key, value interface{}) error {
} }
removed = true removed = true
if err := dirF.Sync(); err != nil { if err := syncDir(dir); err != nil {
return err return err
} }
return nil return nil
} }
......
// +build !windows
package flatfs
import "os"
func syncDir(dir string) error {
dirF, err := os.Open(dir)
if err != nil {
return err
}
defer dirF.Close()
if err := dirF.Sync(); err != nil {
return err
}
return nil
}
package flatfs
func syncDir(dir string) error {
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