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 {
598
598
}
599
599
#endif
600
600
}
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
+ }
601
621
}
602
622
603
623
#if os(Windows)
Original file line number Diff line number Diff line change @@ -54,6 +54,13 @@ internal func system_fsync(_ fd: Int32) -> CInt {
54
54
55
55
#endif
56
56
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
+
57
64
#if os(Linux)
58
65
// posix_fadvise
59
66
internal func system_posix_fadvise(
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ protocol WASIFile: WASIEntry {
25
25
func setFdStatFlags( _ flags: WASIAbi . Fdflags ) throws
26
26
func setFilestatSize( _ size: WASIAbi . FileSize ) throws
27
27
func sync( ) throws
28
+ func datasync( ) throws
28
29
29
30
func tell( ) throws -> WASIAbi . FileSize
30
31
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 {
30
30
}
31
31
}
32
32
33
+ func datasync( ) throws {
34
+ try WASIAbi . Errno. translatingPlatformErrno {
35
+ try fd. datasync ( )
36
+ }
37
+ }
38
+
33
39
@inlinable
34
40
func write< Buffer: Sequence > ( vectored buffer: Buffer ) throws -> WASIAbi . Size where Buffer. Element == WASIAbi . IOVec {
35
41
guard accessMode. contains ( . write) else {
Original file line number Diff line number Diff line change @@ -1516,7 +1516,10 @@ public class WASIBridgeToHost: WASI {
1516
1516
}
1517
1517
1518
1518
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 ( )
1520
1523
}
1521
1524
1522
1525
func fd_fdstat_get( fileDescriptor: UInt32 ) throws -> WASIAbi . FdStat {
You can’t perform that action at this time.
0 commit comments