Skip to content

Commit 09a100b

Browse files
Fix fchown and fchmod calls on WASI by gating them behind os(WASI).
1 parent 2f9c8cc commit 09a100b

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

schemes/main/swift-foundation/1094.patch renamed to schemes/main/swift-foundation/0001-Fix-WASI-build-of-_copyDirectoryMetadata.patch

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
From cc9d6a3535122542a28f3cf8eb93feb95e05b0f5 Mon Sep 17 00:00:00 2001
22
From: Yuta Saito <[email protected]>
33
Date: Fri, 13 Dec 2024 16:09:59 +0000
4-
Subject: [PATCH] Fix WASI build of `_copyDirectoryMetadata`
4+
Subject: [PATCH 1/2] Fix WASI build of `_copyDirectoryMetadata`
55

66
Extended attributes don't exist in WASI, so we need to exclude the use
77
of xattr-related APIs including `flistxattr`.
@@ -10,7 +10,7 @@ of xattr-related APIs including `flistxattr`.
1010
1 file changed, 2 insertions(+)
1111

1212
diff --git a/Sources/FoundationEssentials/FileManager/FileOperations.swift b/Sources/FoundationEssentials/FileManager/FileOperations.swift
13-
index 418f5cfb..9567f65d 100644
13+
index 418f5cf..9567f65 100644
1414
--- a/Sources/FoundationEssentials/FileManager/FileOperations.swift
1515
+++ b/Sources/FoundationEssentials/FileManager/FileOperations.swift
1616
@@ -951,6 +951,7 @@ enum _FileOperations {
@@ -29,3 +29,6 @@ index 418f5cfb..9567f65d 100644
2929
var statInfo = stat()
3030
if fstat(srcFD, &statInfo) == 0 {
3131
// Copy owner/group
32+
--
33+
2.46.0
34+
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)