]> Cypherpunks repositories - gostls13.git/commitdiff
os: add Sync to *File, wraps syscall.Fsync
authorAndrew Gerrand <adg@golang.org>
Wed, 12 Jan 2011 00:08:39 +0000 (11:08 +1100)
committerAndrew Gerrand <adg@golang.org>
Wed, 12 Jan 2011 00:08:39 +0000 (11:08 +1100)
R=rsc, brainman, r, r2
CC=golang-dev
https://golang.org/cl/3887042

src/pkg/os/file.go
src/pkg/syscall/syscall_windows.go

index 909e28e68f92375a600b38e71e76a40c077e9b99..3f73f1dffef6f9da90dd0feb7e1d7f5c2c8815dd 100644 (file)
@@ -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.
 //
index b425337bf5031aed6d625b75adb39bf07ebe2f57..9501779e18f0b5b4e3c7749e493a0378f8b7a49d 100644 (file)
@@ -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 }