os: add os.(*File).Sync
Signed-off-by: Achille Roussel <achille.roussel@gmail.com>
Этот коммит содержится в:
родитель
4fa6a132e2
коммит
ccfe92a58c
8 изменённых файлов: 27 добавлений и 15 удалений
|
@ -247,6 +247,18 @@ func (f *File) Fd() uintptr {
|
||||||
return ^uintptr(0)
|
return ^uintptr(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 (f *File) Sync() (err error) {
|
||||||
|
if f.handle == nil {
|
||||||
|
err = ErrClosed
|
||||||
|
} else {
|
||||||
|
err = f.handle.Sync()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Truncate is a stub, not yet implemented
|
// Truncate is a stub, not yet implemented
|
||||||
func (f *File) Truncate(size int64) (err error) {
|
func (f *File) Truncate(size int64) (err error) {
|
||||||
if f.handle == nil {
|
if f.handle == nil {
|
||||||
|
|
|
@ -140,6 +140,9 @@ var closeTests = map[string]func(*File) error{
|
||||||
_, err := f.Seek(0, 0)
|
_, err := f.Seek(0, 0)
|
||||||
return err
|
return err
|
||||||
},
|
},
|
||||||
|
"Sync": func(f *File) error {
|
||||||
|
return f.Sync()
|
||||||
|
},
|
||||||
"SyscallConn": func(f *File) error {
|
"SyscallConn": func(f *File) error {
|
||||||
_, err := f.SyscallConn()
|
_, err := f.SyscallConn()
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -130,6 +130,11 @@ func (f unixFileHandle) Seek(offset int64, whence int) (int64, error) {
|
||||||
return newoffset, handleSyscallError(err)
|
return newoffset, handleSyscallError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f unixFileHandle) Sync() error {
|
||||||
|
err := syscall.Fsync(syscallFd(f))
|
||||||
|
return handleSyscallError(err)
|
||||||
|
}
|
||||||
|
|
||||||
type unixDirent struct {
|
type unixDirent struct {
|
||||||
parent string
|
parent string
|
||||||
name string
|
name string
|
||||||
|
|
|
@ -90,6 +90,10 @@ func (f unixFileHandle) Seek(offset int64, whence int) (int64, error) {
|
||||||
return newoffset, handleSyscallError(err)
|
return newoffset, handleSyscallError(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f unixFileHandle) Sync() error {
|
||||||
|
return ErrNotImplemented
|
||||||
|
}
|
||||||
|
|
||||||
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
|
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
|
||||||
// True is returned if name is 'NUL' whatever the case.
|
// True is returned if name is 'NUL' whatever the case.
|
||||||
func isWindowsNulName(name string) bool {
|
func isWindowsNulName(name string) bool {
|
||||||
|
|
|
@ -52,6 +52,9 @@ type FileHandle interface {
|
||||||
// Seek resets the file pointer relative to start, current position, or end
|
// Seek resets the file pointer relative to start, current position, or end
|
||||||
Seek(offset int64, whence int) (newoffset int64, err error)
|
Seek(offset int64, whence int) (newoffset int64, err error)
|
||||||
|
|
||||||
|
// Sync blocks until buffered writes have been written to persistent storage
|
||||||
|
Sync() (err error)
|
||||||
|
|
||||||
// Write writes up to len(b) bytes to the file.
|
// Write writes up to len(b) bytes to the file.
|
||||||
Write(b []byte) (n int, err error)
|
Write(b []byte) (n int, err error)
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,6 @@
|
||||||
|
|
||||||
package os
|
package os
|
||||||
|
|
||||||
// Sync is a stub, not yet implemented
|
|
||||||
func (f *File) Sync() error {
|
|
||||||
return ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stat is a stub, not yet implemented
|
// Stat is a stub, not yet implemented
|
||||||
func (f *File) Stat() (FileInfo, error) {
|
func (f *File) Stat() (FileInfo, error) {
|
||||||
return nil, ErrNotImplemented
|
return nil, ErrNotImplemented
|
||||||
|
|
|
@ -10,11 +10,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sync is a stub, not yet implemented
|
|
||||||
func (f *File) Sync() error {
|
|
||||||
return ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stat returns the FileInfo structure describing file.
|
// Stat returns the FileInfo structure describing file.
|
||||||
// If there is an error, it will be of type *PathError.
|
// If there is an error, it will be of type *PathError.
|
||||||
func (f *File) Stat() (FileInfo, error) {
|
func (f *File) Stat() (FileInfo, error) {
|
||||||
|
|
|
@ -10,11 +10,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sync is a stub, not yet implemented
|
|
||||||
func (f *File) Sync() error {
|
|
||||||
return ErrNotImplemented
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stat returns the FileInfo structure describing file.
|
// Stat returns the FileInfo structure describing file.
|
||||||
// If there is an error, it will be of type *PathError.
|
// If there is an error, it will be of type *PathError.
|
||||||
func (file *File) Stat() (FileInfo, error) {
|
func (file *File) Stat() (FileInfo, error) {
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче