summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2011-01-12 11:08:39 +1100
committerAndrew Gerrand <adg@golang.org>2011-01-12 11:08:39 +1100
commit2fe83d6d5abccf000efc7295b2f4bc7097cbb13c (patch)
tree159b4377f0a37ec29b41814725c468b400c3ccb5
parent00948b16453f88e98b22a6acdb2e91db5f61f2c4 (diff)
downloadgo-2fe83d6d5abccf000efc7295b2f4bc7097cbb13c.tar.gz
os: add Sync to *File, wraps syscall.Fsync
R=rsc, brainman, r, r2 CC=golang-dev http://codereview.appspot.com/3887042
-rw-r--r--src/pkg/os/file.go13
-rw-r--r--src/pkg/syscall/syscall_windows.go3
2 files changed, 16 insertions, 0 deletions
diff --git a/src/pkg/os/file.go b/src/pkg/os/file.go
index 909e28e68..3f73f1dff 100644
--- a/src/pkg/os/file.go
+++ b/src/pkg/os/file.go
@@ -408,6 +408,19 @@ func (f *File) Truncate(size int64) Error {
return nil
}
+// Sync commits the current contents of the file to stable storage.
+// Typically, this means flushing the file system's in-memory copy
+// of recently written data to disk.
+func (file *File) Sync() (err Error) {
+ if file == nil {
+ return EINVAL
+ }
+ if e := syscall.Fsync(file.fd); e != 0 {
+ return NewSyscallError("fsync", e)
+ }
+ return nil
+}
+
// Chtimes changes the access and modification times of the named
// file, similar to the Unix utime() or utimes() functions.
//
diff --git a/src/pkg/syscall/syscall_windows.go b/src/pkg/syscall/syscall_windows.go
index b425337bf..9501779e1 100644
--- a/src/pkg/syscall/syscall_windows.go
+++ b/src/pkg/syscall/syscall_windows.go
@@ -684,6 +684,9 @@ func Chown(path string, uid int, gid int) (errno int) { return EWINDOWS }
func Lchown(path string, uid int, gid int) (errno int) { return EWINDOWS }
func Fchown(fd int, uid int, gid int) (errno int) { return EWINDOWS }
+// TODO(brainman): use FlushFileBuffers Windows api to implement Fsync.
+func Fsync(fd int) (errno int) { return EWINDOWS }
+
func Getuid() (uid int) { return -1 }
func Geteuid() (euid int) { return -1 }
func Getgid() (gid int) { return -1 }