Skip to content

Commit

Permalink
Make the FileSystem world strict concurrency clean
Browse files Browse the repository at this point in the history
Motivation:

We have a few other file system modules with a small
amount of code, and a lot of tests. Most of these require
no changes for strict concurrency, so let's tackle them all.

Modifications:

Strict concurrency for filesystem targets enabled.
Fixed a few incorrect test case captures.

Result:

Strict concurrency clean filesystem bits.
  • Loading branch information
Lukasa committed Feb 4, 2025
1 parent ac79370 commit 10066b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
14 changes: 9 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -256,15 +256,17 @@ let package = Package(
dependencies: [
"_NIOFileSystem"
],
path: "Sources/_NIOFileSystemExported"
path: "Sources/_NIOFileSystemExported",
swiftSettings: strictConcurrencySettings
),
.target(
name: "_NIOFileSystemFoundationCompat",
dependencies: [
"_NIOFileSystem",
"NIOFoundationCompat",
],
path: "Sources/NIOFileSystemFoundationCompat"
path: "Sources/NIOFileSystemFoundationCompat",
swiftSettings: strictConcurrencySettings
),

// MARK: - Examples
Expand Down Expand Up @@ -543,7 +545,7 @@ let package = Package(
swiftCollections,
swiftSystem,
],
swiftSettings: [
swiftSettings: strictConcurrencySettings + [
.define("ENABLE_MOCKING", .when(configuration: .debug))
]
),
Expand All @@ -560,14 +562,16 @@ let package = Package(
// for the integration tests. Exclude the whole tree from
// the build.
"Test Data"
]
],
swiftSettings: strictConcurrencySettings
),
.testTarget(
name: "NIOFileSystemFoundationCompatTests",
dependencies: [
"_NIOFileSystem",
"_NIOFileSystemFoundationCompat",
]
],
swiftSettings: strictConcurrencySettings
),
]
)
Expand Down
12 changes: 6 additions & 6 deletions Tests/NIOFileSystemIntegrationTests/FileSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -585,9 +585,9 @@ final class FileSystemTests: XCTestCase {
func testCopyLargeFile() async throws {
let sourcePath = try await self.fs.temporaryFilePath()
let destPath = try await self.fs.temporaryFilePath()
self.addTeardownBlock {
_ = try? await self.fs.removeItem(at: sourcePath, strategy: .platformDefault)
_ = try? await self.fs.removeItem(at: destPath, strategy: .platformDefault)
self.addTeardownBlock { [fs] in
_ = try? await fs.removeItem(at: sourcePath, strategy: .platformDefault)
_ = try? await fs.removeItem(at: destPath, strategy: .platformDefault)
}

let sourceInfo = try await self.fs.withFileHandle(
Expand Down Expand Up @@ -854,7 +854,7 @@ final class FileSystemTests: XCTestCase {
_ copyStrategy: CopyStrategy,
_ description: String,
_ path: FilePath,
triggerCancel: @escaping (DirectoryEntry) -> Bool,
triggerCancel: @escaping @Sendable (DirectoryEntry) -> Bool,
line: UInt = #line
) async throws {

Expand All @@ -863,8 +863,8 @@ final class FileSystemTests: XCTestCase {
let requestedCancel = NIOLockedValueBox<Bool>(false)
let cancelRequested = expectation(description: "cancel requested")

let task = Task {
try await self.fs.copyItem(at: path, to: copyPath, strategy: copyStrategy) { _, error in
let task = Task { [fs] in
try await fs.copyItem(at: path, to: copyPath, strategy: copyStrategy) { _, error in
throw error
} shouldCopyItem: { source, destination in
// Abuse shouldCopy to trigger the cancellation after getting some way in.
Expand Down

0 comments on commit 10066b5

Please sign in to comment.