|
| 1 | +From 88ddc3cc219262ea2c3d421be0333b8625b4d77c Mon Sep 17 00:00:00 2001 |
| 2 | +From: Yuta Saito < [email protected]> |
| 3 | +Date: Sat, 14 Dec 2024 06:48:35 +0000 |
| 4 | +Subject: [PATCH 2/2] Gate `fchown` and `fchmod` calls behind `os(WASI)` |
| 5 | + |
| 6 | +They are not available on WASI, so we gate them behind `os(WASI)`. |
| 7 | +--- |
| 8 | + Sources/FoundationEssentials/FileManager/FileOperations.swift | 4 ++++ |
| 9 | + 1 file changed, 4 insertions(+) |
| 10 | + |
| 11 | +diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift |
| 12 | +index 9567f65..49e2c37 100644 |
| 13 | +--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift |
| 14 | ++++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift |
| 15 | +@@ -980,10 +980,12 @@ enum _FileOperations { |
| 16 | + #endif |
| 17 | + var statInfo = stat() |
| 18 | + if fstat(srcFD, &statInfo) == 0 { |
| 19 | ++ #if !os(WASI) // WASI doesn't have fchown for now |
| 20 | + // Copy owner/group |
| 21 | + if fchown(dstFD, statInfo.st_uid, statInfo.st_gid) != 0 { |
| 22 | + try delegate.throwIfNecessary(errno, srcPath(), dstPath()) |
| 23 | + } |
| 24 | ++ #endif |
| 25 | + |
| 26 | + // Copy modification date |
| 27 | + let value = timeval(tv_sec: statInfo.st_mtim.tv_sec, tv_usec: statInfo.st_mtim.tv_nsec / 1000) |
| 28 | +@@ -996,10 +998,12 @@ enum _FileOperations { |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | ++ #if !os(WASI) // WASI doesn't have fchmod for now |
| 33 | + // Copy permissions |
| 34 | + if fchmod(dstFD, mode_t(statInfo.st_mode)) != 0 { |
| 35 | + try delegate.throwIfNecessary(errno, srcPath(), dstPath()) |
| 36 | + } |
| 37 | ++ #endif |
| 38 | + } else { |
| 39 | + try delegate.throwIfNecessary(errno, srcPath(), dstPath()) |
| 40 | + } |
| 41 | +-- |
| 42 | +2.46.0 |
| 43 | + |
0 commit comments