@@ -388,6 +388,43 @@ index d515a63f..fb037e24 100644
388
388
#endif
389
389
390
390
enum HelperCheckStatus : Int32 {
391
+ From 7e0817f4c7dbc748fc70c45c20edd5acc98a34d7
392
+ From: Yuta Saito <
[email protected] >
393
+ Date: Tue, 17 Dec 2024 04:19:39 +0900
394
+ Subject: [PATCH] Follow-up fixes to make it work with wasi-libc (#1095)
395
+
396
+ * Use `futimens` instead of legacy `futimes`
397
+
398
+ wasi-libc does not provide `futimes` as it is a legacy function.
399
+ https://github.com/WebAssembly/wasi-libc/blob/574b88da481569b65a237cb80daf9a2d5aeaf82d/libc-top-half/musl/include/sys/time.h#L34
400
+
401
+ diff --git a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift
402
+ index ce4de44a..96ee566d 100644
403
+ --- a/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift
404
+ +++ b/swift-foundation/Sources/FoundationEssentials/FileManager/FileOperations.swift
405
+ @@ -940,17 +940,19 @@ enum _FileOperations {
406
+ #endif
407
+ var statInfo = stat()
408
+ if fstat(srcFD, &statInfo) == 0 {
409
+ + #if !os(WASI) // WASI doesn't have fchown for now
410
+ // Copy owner/group
411
+ if fchown(dstFD, statInfo.st_uid, statInfo.st_gid) != 0 {
412
+ try delegate.throwIfNecessary(errno, srcPath(), dstPath())
413
+ }
414
+ + #endif
415
+
416
+ // Copy modification date
417
+ - let value = timeval(tv_sec: statInfo.st_mtim.tv_sec, tv_usec: statInfo.st_mtim.tv_nsec / 1000)
418
+ + let value = statInfo.st_mtim
419
+ var tv = (value, value)
420
+ try withUnsafePointer(to: &tv) {
421
+ - try $0.withMemoryRebound(to: timeval.self, capacity: 2) {
422
+ - if futimes(dstFD, $0) != 0 {
423
+ + try $0.withMemoryRebound(to: timespec.self, capacity: 2) {
424
+ + if futimens(dstFD, $0) != 0 {
425
+ try delegate.throwIfNecessary(errno, srcPath(), dstPath())
426
+ }
427
+ }
391
428
commit 4339393f2c1f3bceaf20bc2c25ee828a2e0394aa
392
429
Author: Alex Lorenz <
[email protected] >
393
430
Date: Thu Dec 12 07:34:34 2024 -0800
0 commit comments