From e4e12848fb5e9b4d3d4fa8a8d18e155dfb56af5d Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Tue, 24 Mar 2015 12:31:16 +1100 Subject: [PATCH] Fixed fdatasync build errors on darwin. --- fsutil/fsutil.go | 7 +++++++ samples/flushfs/flush_fs_test.go | 14 +++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/fsutil/fsutil.go b/fsutil/fsutil.go index 152ef85..b21732b 100644 --- a/fsutil/fsutil.go +++ b/fsutil/fsutil.go @@ -48,3 +48,10 @@ func AnonymousFile(dir string) (f *os.File, err error) { return } + +// Call fdatasync on the supplied file. +// +// REQUIRES: FdatasyncSupported is true. +func Fdatasync(f *os.File) error { + return fdatasync(f) +} diff --git a/samples/flushfs/flush_fs_test.go b/samples/flushfs/flush_fs_test.go index 4eab497..f58a037 100644 --- a/samples/flushfs/flush_fs_test.go +++ b/samples/flushfs/flush_fs_test.go @@ -413,6 +413,10 @@ func (t *NoErrorsTest) Fdatasync() { var n int var err error + if !fsutil.FdatasyncSupported { + return + } + // Open the file. t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_WRONLY, 0) AssertEq(nil, err) @@ -426,7 +430,7 @@ func (t *NoErrorsTest) Fdatasync() { AssertThat(t.getFsyncs(), ElementsAre()) // Fdatasync. - err = syscall.Fdatasync(int(t.f1.Fd())) + err = fsutil.Fdatasync(t.f1) AssertEq(nil, err) AssertThat(t.getFlushes(), ElementsAre()) @@ -441,7 +445,7 @@ func (t *NoErrorsTest) Fdatasync() { AssertThat(t.getFsyncs(), ElementsAre("taco")) // Fdatasync. - err = syscall.Fdatasync(int(t.f1.Fd())) + err = fsutil.Fdatasync(t.f1) AssertEq(nil, err) AssertThat(t.getFlushes(), ElementsAre()) @@ -789,12 +793,16 @@ func (t *FsyncErrorTest) Fsync() { func (t *FsyncErrorTest) Fdatasync() { var err error + if !fsutil.FdatasyncSupported { + return + } + // Open the file. t.f1, err = os.OpenFile(path.Join(t.Dir, "foo"), os.O_RDWR, 0) AssertEq(nil, err) // Fdatasync. - err = syscall.Fdatasync(int(t.f1.Fd())) + err = fsutil.Fdatasync(t.f1) ExpectThat(err, Error(HasSubstr("no such file"))) }