forked from finagolfin/swift-android-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swift-nio-filesystem.patch
264 lines (236 loc) · 11.5 KB
/
swift-nio-filesystem.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
diff --git a/Sources/NIOFileSystem/FileSystem.swift b/Sources/NIOFileSystem/FileSystem.swift
index 3fc7d561..50e0482a 100644
--- a/Sources/NIOFileSystem/FileSystem.swift
+++ b/Sources/NIOFileSystem/FileSystem.swift
@@ -17,6 +17,7 @@
import NIOCore
import NIOPosix
import SystemPackage
+import class Foundation.FileManager
#if canImport(Darwin)
import Darwin
@@ -626,7 +627,8 @@ public struct FileSystem: Sendable, FileSystemProtocol {
}.get()
}
#elseif os(Android)
- return "/data/local/tmp"
+ //return "/data/local/tmp"
+ return FilePath(FileManager.default.temporaryDirectory.path)
#else
return "/tmp"
#endif
diff --git a/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift b/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift
index 1e9c1661..2a4935e7 100644
--- a/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift
+++ b/Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift
@@ -452,12 +452,21 @@ internal func libc_confstr(
#endif
/// fts(3)
+#if compiler(<6.1)
+internal func libc_fts_open(
+ _ path: [UnsafeMutablePointer<CInterop.PlatformChar>],
+ _ options: CInt
+) -> UnsafeMutablePointer<CInterop.FTS> {
+ fts_open(path, options, nil)!
+}
+#else
internal func libc_fts_open(
_ path: [UnsafeMutablePointer<CInterop.PlatformChar>?],
_ options: CInt
) -> UnsafeMutablePointer<CInterop.FTS> {
fts_open(path, options, nil)!
}
+#endif
/// fts(3)
internal func libc_fts_read(
diff --git a/Sources/NIOFileSystem/Internal/SystemFileHandle.swift b/Sources/NIOFileSystem/Internal/SystemFileHandle.swift
index 3dc51872..49aeeeca 100644
--- a/Sources/NIOFileSystem/Internal/SystemFileHandle.swift
+++ b/Sources/NIOFileSystem/Internal/SystemFileHandle.swift
@@ -1113,7 +1113,7 @@ extension SystemFileHandle {
let truncate = options.contains(.truncate)
let delayMaterialization = transactional && isWritable && (exclusiveCreate || truncate)
- if delayMaterialization {
+ if false {
// When opening in this mode we can more "atomically" create the file, that is, by not
// leaving the user with a half written file should e.g. the system crash or throw an
// error while writing. On non-Android Linux we do this by opening the directory for
diff --git a/Tests/NIOFileSystemIntegrationTests/BufferedReaderTests.swift b/Tests/NIOFileSystemIntegrationTests/BufferedReaderTests.swift
index 8404e159..151fccc1 100644
--- a/Tests/NIOFileSystemIntegrationTests/BufferedReaderTests.swift
+++ b/Tests/NIOFileSystemIntegrationTests/BufferedReaderTests.swift
@@ -21,7 +21,7 @@ import XCTest
final class BufferedReaderTests: XCTestCase {
func testBufferedReaderSizeAndCapacity() async throws {
let fs = FileSystem.shared
- try await fs.withFileHandle(forReadingAt: #filePath) { handle in
+ try await fs.withFileHandle(forReadingAt: "/data/data/com.termux/pack/FileHandleTests.swift") { handle in
var reader = handle.bufferedReader(capacity: .bytes(128 * 1024))
XCTAssertEqual(reader.count, 0)
XCTAssertEqual(reader.capacity, 128 * 1024)
@@ -88,7 +88,7 @@ final class BufferedReaderTests: XCTestCase {
func testBufferedReaderReadingShort() async throws {
let fs = FileSystem.shared
- try await fs.withFileHandle(forReadingAt: #filePath) { handle in
+ try await fs.withFileHandle(forReadingAt: "/data/data/com.termux/pack/FileHandleTests.swift") { handle in
var reader = handle.bufferedReader(capacity: .bytes(128))
var buffer = ByteBuffer()
while true {
diff --git a/Tests/NIOFileSystemIntegrationTests/FileHandleTests.swift b/Tests/NIOFileSystemIntegrationTests/FileHandleTests.swift
index c18e2c8e..65872fb9 100644
--- a/Tests/NIOFileSystemIntegrationTests/FileHandleTests.swift
+++ b/Tests/NIOFileSystemIntegrationTests/FileHandleTests.swift
@@ -20,9 +20,8 @@ import XCTest
@available(macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
final class FileHandleTests: XCTestCase {
- static let thisFile = FilePath(#filePath)
- static let testData = FilePath(#filePath)
- .removingLastComponent() // FileHandleTests.swift
+ static let thisFile = FilePath("/data/data/com.termux/pack/FileHandleTests.swift")
+ static let testData = FilePath("/data/data/com.termux/pack/")
.appending("Test Data")
.lexicallyNormalized()
@@ -995,7 +994,7 @@ final class FileHandleTests: XCTestCase {
}
}
- func testOpenExclusiveCreateForFileWhichExistsWithoutOTMPFILE() async throws {
+ /*func testOpenExclusiveCreateForFileWhichExistsWithoutOTMPFILE() async throws {
// Takes the path where 'O_TMPFILE' doesn't exist, so materializing the file is done via
// creating a temporary file and then renaming it using 'renamex_np'/'renameat2' (Darwin/Linux).
let temporaryDirectory = try await FileSystem.shared.temporaryDirectory
@@ -1013,7 +1012,7 @@ final class FileHandleTests: XCTestCase {
try await handle.close()
let info = try await FileSystem.shared.info(forFileAt: path)
XCTAssertNotNil(info)
- }
+ }*/
func testOpenExclusiveCreateForFileWhichExistsWithoutOTMPFILEOrRenameat2() async throws {
// Takes the path where 'O_TMPFILE' doesn't exist, so materializing the file is done via
diff --git a/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift b/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift
index f24736a7..310d9691 100644
--- a/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift
+++ b/Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift
@@ -19,8 +19,8 @@ import NIOCore
@_spi(Testing) @testable import _NIOFileSystem
extension FilePath {
- static let testData = FilePath(#filePath)
- .removingLastComponent() // FileHandleTests.swift
+ static let testFile = FilePath("/data/data/com.termux/pack/FileHandleTests.swift")
+ static let testData = FilePath("/data/data/com.termux/pack/")
.appending("Test Data")
.lexicallyNormalized()
@@ -100,7 +100,7 @@ final class FileSystemTests: XCTestCase {
}
func testOpenFileWhereIntermediateIsNotADirectory() async throws {
- let path = FilePath(#filePath).appending("foobar")
+ let path = FilePath.testFile.appending("foobar")
// For reading:
await XCTAssertThrowsFileSystemErrorAsync {
@@ -183,7 +183,7 @@ final class FileSystemTests: XCTestCase {
XCTAssertEqual(contents, ByteBuffer(bytes: [0, 1, 2]))
}
- func testOpenNonExistentFileForWritingWithMaterialization() async throws {
+ /*func testOpenNonExistentFileForWritingWithMaterialization() async throws {
for isAbsolute in [true, false] {
let path = try await self.fs.temporaryFilePath(inTemporaryDirectory: isAbsolute)
XCTAssertEqual(path.isAbsolute, isAbsolute)
@@ -256,7 +256,7 @@ final class FileSystemTests: XCTestCase {
XCTAssertEqual(buffer.readBytes(length: 1024), Array(repeating: 0, count: 1024))
XCTAssertEqual(buffer.readBytes(length: 1024), Array(repeating: 1, count: 1024))
XCTAssertEqual(buffer.readableBytes, 0)
- }
+ }*/
func testOpenFileForReadingAndWriting() async throws {
let path = try await self.fs.temporaryFilePath()
@@ -315,7 +315,7 @@ final class FileSystemTests: XCTestCase {
}
}
- func testOpenNonExistentFileForWritingRelativeToDirectoryWithMaterialization() async throws {
+ /*func testOpenNonExistentFileForWritingRelativeToDirectoryWithMaterialization() async throws {
// (false, false) isn't supported.
let isPathAbsolute: [(Bool, Bool)] = [(true, true), (true, false), (false, true)]
@@ -419,7 +419,7 @@ final class FileSystemTests: XCTestCase {
}
}
}
- }
+ }*/
func testCreateDirectory() async throws {
let path = try await self.fs.temporaryFilePath()
@@ -559,7 +559,7 @@ final class FileSystemTests: XCTestCase {
}
}
- func testCopyLargeFile() async throws {
+/* func testCopyLargeFile() async throws {
let sourcePath = try await self.fs.temporaryFilePath()
let destPath = try await self.fs.temporaryFilePath()
self.addTeardownBlock {
@@ -584,7 +584,7 @@ final class FileSystemTests: XCTestCase {
try await self.fs.copyItem(at: sourcePath, to: destPath)
let destInfo = try await self.fs.info(forFileAt: destPath)
XCTAssertEqual(destInfo?.size, sourceInfo.size)
- }
+ }*/
func testCopySingleFileCopiesAttributesAndPermissions() async throws {
let original = try await self.fs.temporaryFilePath()
@@ -1284,7 +1284,7 @@ extension FileSystemTests {
}
func testReadChunksRange() async throws {
- try await self.fs.withFileHandle(forReadingAt: FilePath(#filePath)) { handle in
+ try await self.fs.withFileHandle(forReadingAt: FilePath.testFile) { handle in
let info = try await handle.info()
let size = info.size
let endIndex = size + 1
@@ -1310,7 +1310,7 @@ extension FileSystemTests {
}
func testReadChunksClosedRange() async throws {
- try await self.fs.withFileHandle(forReadingAt: FilePath(#filePath)) { handle in
+ try await self.fs.withFileHandle(forReadingAt: FilePath.testFile) { handle in
let info = try await handle.info()
let size = info.size
let endIndex = size + 1
@@ -1337,7 +1337,7 @@ extension FileSystemTests {
}
func testReadChunksPartialRangeUpTo() async throws {
- try await self.fs.withFileHandle(forReadingAt: FilePath(#filePath)) { handle in
+ try await self.fs.withFileHandle(forReadingAt: FilePath.testFile) { handle in
let info = try await handle.info()
let size = info.size
let endIndex = size + 1
@@ -1365,7 +1365,7 @@ extension FileSystemTests {
}
func testReadChunksPartialRangeThrough() async throws {
- try await self.fs.withFileHandle(forReadingAt: FilePath(#filePath)) { handle in
+ try await self.fs.withFileHandle(forReadingAt: FilePath.testFile) { handle in
let info = try await handle.info()
let size = info.size
let endIndex = size + 1
@@ -1394,7 +1394,7 @@ extension FileSystemTests {
}
func testReadChunksPartialRangeFrom() async throws {
- try await self.fs.withFileHandle(forReadingAt: FilePath(#filePath)) { handle in
+ try await self.fs.withFileHandle(forReadingAt: FilePath.testFile) { handle in
let info = try await handle.info()
let size = info.size
let endIndex = size + 1
@@ -1418,7 +1418,7 @@ extension FileSystemTests {
}
func testReadChunksUnboundedRange() async throws {
- try await self.fs.withFileHandle(forReadingAt: FilePath(#filePath)) { handle in
+ try await self.fs.withFileHandle(forReadingAt: FilePath.testFile) { handle in
let info = try await handle.info()
let size = info.size
diff --git a/Tests/NIOFileSystemTests/Internal/SyscallTests.swift b/Tests/NIOFileSystemTests/Internal/SyscallTests.swift
index 66ed1171..5253a650 100644
--- a/Tests/NIOFileSystemTests/Internal/SyscallTests.swift
+++ b/Tests/NIOFileSystemTests/Internal/SyscallTests.swift
@@ -17,6 +17,10 @@
import XCTest
@_spi(Testing) import _NIOFileSystem
+#if canImport(Android)
+import Android
+#endif
+
#if ENABLE_MOCKING
final class SyscallTests: XCTestCase {
func test_openat() throws {