diff --git a/Sources/NIOFileSystem/BufferedWriter.swift b/Sources/NIOFileSystem/BufferedWriter.swift index 682bbb19e..beb57146e 100644 --- a/Sources/NIOFileSystem/BufferedWriter.swift +++ b/Sources/NIOFileSystem/BufferedWriter.swift @@ -196,7 +196,7 @@ extension WritableFileHandleProtocol { /// buffer to the file system when it exceeds this capacity. Defaults to 512 KiB. /// - body: The closure that writes the contents to the buffer created in this method. /// - Returns: The result of the executed closure. - public func withBufferedWriter( + public func withBufferedWriter( startingAtAbsoluteOffset initialOffset: Int64 = 0, capacity: ByteCount = .kibibytes(512), execute body: (inout BufferedWriter) async throws -> R diff --git a/Sources/NIOFileSystem/FileHandleProtocol.swift b/Sources/NIOFileSystem/FileHandleProtocol.swift index ce92de86d..2103caa93 100644 --- a/Sources/NIOFileSystem/FileHandleProtocol.swift +++ b/Sources/NIOFileSystem/FileHandleProtocol.swift @@ -581,7 +581,7 @@ extension DirectoryFileHandleProtocol { /// automatically after the closure exits. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withFileHandle( + public func withFileHandle( forReadingAt path: FilePath, options: OpenOptions.Read = OpenOptions.Read(), execute body: (_ read: ReadFileHandle) async throws -> R @@ -612,7 +612,7 @@ extension DirectoryFileHandleProtocol { /// automatically after the closure exits. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withFileHandle( + public func withFileHandle( forWritingAt path: FilePath, options: OpenOptions.Write = .newFile(replaceExisting: false), execute body: (_ write: WriteFileHandle) async throws -> R @@ -647,7 +647,7 @@ extension DirectoryFileHandleProtocol { /// automatically after the closure exits. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withFileHandle( + public func withFileHandle( forReadingAndWritingAt path: FilePath, options: OpenOptions.Write = .newFile(replaceExisting: false), execute body: (_ readWrite: ReadWriteFileHandle) async throws -> R @@ -673,7 +673,7 @@ extension DirectoryFileHandleProtocol { /// - body: A closure which provides access to the directory. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withDirectoryHandle( + public func withDirectoryHandle( atPath path: FilePath, options: OpenOptions.Directory = OpenOptions.Directory(), execute body: (_ directory: Self) async throws -> R diff --git a/Sources/NIOFileSystem/FileSystem.swift b/Sources/NIOFileSystem/FileSystem.swift index 1062e46f6..887cf6318 100644 --- a/Sources/NIOFileSystem/FileSystem.swift +++ b/Sources/NIOFileSystem/FileSystem.swift @@ -700,7 +700,7 @@ extension FileSystemProtocol where Self == FileSystem { /// Provides temporary scoped access to a ``FileSystem`` with the given number of threads. @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public func withFileSystem( +public func withFileSystem( numberOfThreads: Int, _ body: (FileSystem) async throws -> R ) async throws -> R { diff --git a/Sources/NIOFileSystem/FileSystemProtocol.swift b/Sources/NIOFileSystem/FileSystemProtocol.swift index bd1ed6d18..803e08a73 100644 --- a/Sources/NIOFileSystem/FileSystemProtocol.swift +++ b/Sources/NIOFileSystem/FileSystemProtocol.swift @@ -274,7 +274,7 @@ extension FileSystemProtocol { /// automatically after the closure exits. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withFileHandle( + public func withFileHandle( forReadingAt path: FilePath, options: OpenOptions.Read = OpenOptions.Read(), execute: (_ read: ReadFileHandle) async throws -> R @@ -301,7 +301,7 @@ extension FileSystemProtocol { /// automatically after the closure exits. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withFileHandle( + public func withFileHandle( forWritingAt path: FilePath, options: OpenOptions.Write = .newFile(replaceExisting: false), execute: (_ write: WriteFileHandle) async throws -> R @@ -333,7 +333,7 @@ extension FileSystemProtocol { /// automatically after the closure exits. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withFileHandle( + public func withFileHandle( forReadingAndWritingAt path: FilePath, options: OpenOptions.Write = .newFile(replaceExisting: false), execute: (_ readWrite: ReadWriteFileHandle) async throws -> R @@ -354,7 +354,7 @@ extension FileSystemProtocol { /// - execute: A closure which provides access to the directory. /// - Important: The handle passed to `execute` must not escape the closure. /// - Returns: The result of the `execute` closure. - public func withDirectoryHandle( + public func withDirectoryHandle( atPath path: FilePath, options: OpenOptions.Directory = OpenOptions.Directory(), execute: (_ directory: DirectoryFileHandle) async throws -> R diff --git a/Sources/NIOFileSystem/Internal/Cancellation.swift b/Sources/NIOFileSystem/Internal/Cancellation.swift index 58dbf05df..4316c8867 100644 --- a/Sources/NIOFileSystem/Internal/Cancellation.swift +++ b/Sources/NIOFileSystem/Internal/Cancellation.swift @@ -31,9 +31,9 @@ public func withoutCancellation( /// Executes `fn` and then `tearDown`, which cannot be cancelled. @_spi(Testing) @available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *) -public func withUncancellableTearDown( +public func withUncancellableTearDown( _ fn: () async throws -> R, - tearDown: @escaping (Result) async throws -> Void + tearDown: @escaping (Result) async throws -> Void ) async throws -> R { let result: Result do { @@ -42,9 +42,10 @@ public func withUncancellableTearDown( result = .failure(error) } + let errorOnlyResult: Result = result.map { _ in return () } let tearDownResult: Result = try await withoutCancellation { do { - return .success(try await tearDown(result)) + return .success(try await tearDown(errorOnlyResult)) } catch { return .failure(error) }