File tree Expand file tree Collapse file tree 5 files changed +38
-1
lines changed Expand file tree Collapse file tree 5 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -598,6 +598,26 @@ extension FileDescriptor {
598598 }
599599 #endif
600600 }
601+
602+ public func datasync( ) throws {
603+ return try _datasync ( ) . get ( )
604+ }
605+
606+ internal func _datasync( ) -> Result < Void , Errno > {
607+ #if os(Windows)
608+ return self . _sync ( )
609+ #else
610+ nothingOrErrno ( retryOnInterrupt: false ) {
611+ #if SYSTEM_PACKAGE_DARWIN
612+ system_fcntl ( self . rawValue, F_FULLFSYNC)
613+ #elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(Cygwin) || os(PS4)
614+ system_fdatasync ( self . rawValue)
615+ #else
616+ system_fsync ( self . rawValue)
617+ #endif
618+ }
619+ #endif
620+ }
601621}
602622
603623#if os(Windows)
Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ internal func system_fsync(_ fd: Int32) -> CInt {
5454
5555#endif
5656
57+ #if os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(Cygwin) || os(PS4)
58+ // fdatasync
59+ internal func system_fdatasync( _ fd: Int32 ) -> CInt {
60+ return fdatasync ( fd)
61+ }
62+ #endif
63+
5764#if os(Linux)
5865// posix_fadvise
5966internal func system_posix_fadvise(
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ protocol WASIFile: WASIEntry {
2525 func setFdStatFlags( _ flags: WASIAbi . Fdflags ) throws
2626 func setFilestatSize( _ size: WASIAbi . FileSize ) throws
2727 func sync( ) throws
28+ func datasync( ) throws
2829
2930 func tell( ) throws -> WASIAbi . FileSize
3031 func seek( offset: WASIAbi . FileDelta , whence: WASIAbi . Whence ) throws -> WASIAbi . FileSize
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ extension FdWASIFile {
3030 }
3131 }
3232
33+ func datasync( ) throws {
34+ try WASIAbi . Errno. translatingPlatformErrno {
35+ try fd. datasync ( )
36+ }
37+ }
38+
3339 @inlinable
3440 func write< Buffer: Sequence > ( vectored buffer: Buffer ) throws -> WASIAbi . Size where Buffer. Element == WASIAbi . IOVec {
3541 guard accessMode. contains ( . write) else {
Original file line number Diff line number Diff line change @@ -1516,7 +1516,10 @@ public class WASIBridgeToHost: WASI {
15161516 }
15171517
15181518 func fd_datasync( fd: WASIAbi . Fd ) throws {
1519- throw WASIAbi . Errno. ENOTSUP
1519+ guard case let . file( fileEntry) = fdTable [ fd] else {
1520+ throw WASIAbi . Errno. EBADF
1521+ }
1522+ return try fileEntry. datasync ( )
15201523 }
15211524
15221525 func fd_fdstat_get( fileDescriptor: UInt32 ) throws -> WASIAbi . FdStat {
You can’t perform that action at this time.
0 commit comments