mirror of
https://github.com/apple/swift-nio
synced 2026-11-26 04:57:49 +00:00
Adopt swift-format (#2794)
* Apply formatting
* Apply no block comments rule
* Apply OmitExplicitReturns
* Apple OnlyOneTrailingClosureArgument
* Apply NoAssignmentInExpressions
* Fix up DontRepeatTypeInStaticProperties lint errors
* Apply `OrderedImports`
* Apply `ReplaceForEachWithForLoop`
* format file
* Enable the formatting pipeline
* Adopt `AmbiguousTrailingClosureOverload`
* Fix license header
* Fix format check
* Fix `EndOfLineComment`
* Fix CI
* Adapt CI script to check if changes when running formatting
* Separate lint and format into to steps
* Fix format
* Adopt `UseEarlyExits`
* Revert "Adopt `UseEarlyExits`"
This reverts commit d1ac5bbe12.
This commit is contained in:
1 parent
980bd3e630
commit
c9756e1083
374 files changed
+23992
-14890
No files matched your search
@@ -44,7 +44,7 @@ public struct BufferedReader<Handle: ReadableFileHandleProtocol> {
|
||||
|
||||
/// The number of bytes currently in the buffer.
|
||||
public var count: Int {
|
||||
return self.buffer.readableBytes
|
||||
self.buffer.readableBytes
|
||||
}
|
||||
|
||||
internal init(wrapping readableHandle: Handle, initialOffset: Int64, capacity: Int) {
|
||||
@@ -106,20 +106,6 @@ public struct BufferedReader<Handle: ReadableFileHandleProtocol> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads from the current position in the file until `predicate` returns `false` and returns
|
||||
/// the read bytes.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - predicate: A predicate which evaluates to `true` for all bytes returned.
|
||||
/// - Returns: The bytes read from the file.
|
||||
/// - Important: This method has been deprecated: use ``read(while:)-8aukk`` instead.
|
||||
@available(*, deprecated, message: "Use the read(while:) method returning a (ByteBuffer, Bool) tuple instead.")
|
||||
public mutating func read(
|
||||
while predicate: (UInt8) -> Bool
|
||||
) async throws -> ByteBuffer {
|
||||
try await self.read(while: predicate).bytes
|
||||
}
|
||||
|
||||
/// Reads from the current position in the file until `predicate` returns `false` and returns
|
||||
/// the read bytes.
|
||||
///
|
||||
@@ -139,7 +125,7 @@ public struct BufferedReader<Handle: ReadableFileHandleProtocol> {
|
||||
let prefix = view[..<index]
|
||||
let buffer = ByteBuffer(prefix)
|
||||
self.buffer.moveReaderIndex(forwardBy: buffer.readableBytes)
|
||||
|
||||
|
||||
// If we reached this codepath, it's because at least one element
|
||||
// in the buffer makes the predicate false. This means that we have
|
||||
// stopped reading because the condition doesn't hold true anymore.
|
||||
@@ -221,6 +207,24 @@ public struct BufferedReader<Handle: ReadableFileHandleProtocol> {
|
||||
}
|
||||
}
|
||||
|
||||
// swift-format-ignore: AmbiguousTrailingClosureOverload
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
extension BufferedReader {
|
||||
/// Reads from the current position in the file until `predicate` returns `false` and returns
|
||||
/// the read bytes.
|
||||
///
|
||||
/// - Parameters:
|
||||
/// - predicate: A predicate which evaluates to `true` for all bytes returned.
|
||||
/// - Returns: The bytes read from the file.
|
||||
/// - Important: This method has been deprecated: use ``read(while:)-8aukk`` instead.
|
||||
@available(*, deprecated, message: "Use the read(while:) method returning a (ByteBuffer, Bool) tuple instead.")
|
||||
public mutating func read(
|
||||
while predicate: (UInt8) -> Bool
|
||||
) async throws -> ByteBuffer {
|
||||
try await self.read(while: predicate).bytes
|
||||
}
|
||||
}
|
||||
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
extension ReadableFileHandleProtocol {
|
||||
/// Creates a new ``BufferedReader`` for this file handle.
|
||||
@@ -233,7 +237,7 @@ extension ReadableFileHandleProtocol {
|
||||
startingAtAbsoluteOffset initialOffset: Int64 = 0,
|
||||
capacity: ByteCount = .kibibytes(512)
|
||||
) -> BufferedReader<Self> {
|
||||
return BufferedReader(wrapping: self, initialOffset: initialOffset, capacity: Int(capacity.bytes))
|
||||
BufferedReader(wrapping: self, initialOffset: initialOffset, capacity: Int(capacity.bytes))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,13 +50,13 @@ public struct BufferedWriter<Handle: WritableFileHandleProtocol> {
|
||||
///
|
||||
/// You can flush the buffer manually by calling ``flush()``.
|
||||
public var bufferedBytes: Int {
|
||||
return self.buffer.count
|
||||
self.buffer.count
|
||||
}
|
||||
|
||||
/// The capacity of the buffer.
|
||||
@_spi(Testing)
|
||||
public var bufferCapacity: Int {
|
||||
return self.buffer.capacity
|
||||
self.buffer.capacity
|
||||
}
|
||||
|
||||
internal init(wrapping writableHandle: Handle, initialOffset: Int64, capacity: Int) {
|
||||
@@ -215,13 +215,13 @@ extension WritableFileHandleProtocol {
|
||||
startingAtAbsoluteOffset initialOffset: Int64 = 0,
|
||||
capacity: ByteCount = .kibibytes(512)
|
||||
) -> BufferedWriter<Self> {
|
||||
return BufferedWriter(
|
||||
BufferedWriter(
|
||||
wrapping: self,
|
||||
initialOffset: initialOffset,
|
||||
capacity: Int(capacity.bytes)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/// Convenience function that creates a buffered reader, executes
|
||||
/// the closure that writes the contents into the buffer and calls 'flush()'.
|
||||
///
|
||||
@@ -238,7 +238,7 @@ extension WritableFileHandleProtocol {
|
||||
) async throws -> Result {
|
||||
var bufferedWriter = self.bufferedWriter(startingAtAbsoluteOffset: initialOffset, capacity: capacity)
|
||||
return try await withUncancellableTearDown {
|
||||
return try await body(&bufferedWriter)
|
||||
try await body(&bufferedWriter)
|
||||
} tearDown: { _ in
|
||||
try await bufferedWriter.flush()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
/// Returns a ``ByteCount`` with a given number of bytes
|
||||
/// - Parameter count: The number of bytes
|
||||
public static func bytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: count)
|
||||
ByteCount(bytes: count)
|
||||
}
|
||||
|
||||
/// Returns a ``ByteCount`` with a given number of kilobytes
|
||||
@@ -31,7 +31,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
///
|
||||
/// - Parameter count: The number of kilobytes
|
||||
public static func kilobytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: 1000 * count)
|
||||
ByteCount(bytes: 1000 * count)
|
||||
}
|
||||
|
||||
/// Returns a ``ByteCount`` with a given number of megabytes
|
||||
@@ -40,7 +40,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
///
|
||||
/// - Parameter count: The number of megabytes
|
||||
public static func megabytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: 1000 * 1000 * count)
|
||||
ByteCount(bytes: 1000 * 1000 * count)
|
||||
}
|
||||
|
||||
/// Returns a ``ByteCount`` with a given number of gigabytes
|
||||
@@ -49,7 +49,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
///
|
||||
/// - Parameter count: The number of gigabytes
|
||||
public static func gigabytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: 1000 * 1000 * 1000 * count)
|
||||
ByteCount(bytes: 1000 * 1000 * 1000 * count)
|
||||
}
|
||||
|
||||
/// Returns a ``ByteCount`` with a given number of kibibytes
|
||||
@@ -58,7 +58,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
///
|
||||
/// - Parameter count: The number of kibibytes
|
||||
public static func kibibytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: 1024 * count)
|
||||
ByteCount(bytes: 1024 * count)
|
||||
}
|
||||
|
||||
/// Returns a ``ByteCount`` with a given number of mebibytes
|
||||
@@ -67,7 +67,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
///
|
||||
/// - Parameter count: The number of mebibytes
|
||||
public static func mebibytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: 1024 * 1024 * count)
|
||||
ByteCount(bytes: 1024 * 1024 * count)
|
||||
}
|
||||
|
||||
/// Returns a ``ByteCount`` with a given number of gibibytes
|
||||
@@ -76,7 +76,7 @@ public struct ByteCount: Hashable, Sendable {
|
||||
///
|
||||
/// - Parameter count: The number of gibibytes
|
||||
public static func gibibytes(_ count: Int64) -> ByteCount {
|
||||
return ByteCount(bytes: 1024 * 1024 * 1024 * count)
|
||||
ByteCount(bytes: 1024 * 1024 * 1024 * count)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public struct DirectoryEntries: AsyncSequence {
|
||||
}
|
||||
|
||||
public func makeAsyncIterator() -> DirectoryIterator {
|
||||
return DirectoryIterator(iterator: self.batchedSequence.makeAsyncIterator())
|
||||
DirectoryIterator(iterator: self.batchedSequence.makeAsyncIterator())
|
||||
}
|
||||
|
||||
/// Returns a sequence of directory entry batches.
|
||||
@@ -49,7 +49,7 @@ public struct DirectoryEntries: AsyncSequence {
|
||||
/// than `DirectoryEntry`. This can enable better performance by reducing the number of
|
||||
/// executor hops.
|
||||
public func batched() -> Batched {
|
||||
return self.batchedSequence
|
||||
self.batchedSequence
|
||||
}
|
||||
|
||||
/// An `AsyncIteratorProtocol` of `DirectoryEntry`.
|
||||
@@ -111,7 +111,7 @@ extension DirectoryEntries {
|
||||
}
|
||||
|
||||
public func makeAsyncIterator() -> BatchedIterator {
|
||||
return BatchedIterator(wrapping: self.stream.makeAsyncIterator())
|
||||
BatchedIterator(wrapping: self.stream.makeAsyncIterator())
|
||||
}
|
||||
|
||||
/// An `AsyncIteratorProtocol` of `Array<DirectoryEntry>`.
|
||||
@@ -208,7 +208,7 @@ private struct DirectoryEntryProducer {
|
||||
}
|
||||
|
||||
private func nextBatch() throws -> [DirectoryEntry] {
|
||||
return try self.state.withLockedValue { state in
|
||||
try self.state.withLockedValue { state in
|
||||
try state.next(self.entriesPerBatch)
|
||||
}
|
||||
}
|
||||
@@ -422,7 +422,7 @@ private struct DirectoryEnumerator: Sendable {
|
||||
private mutating func makeReaddirSource(
|
||||
_ handle: SystemFileHandle.SendableView
|
||||
) -> Result<Source, FileSystemError> {
|
||||
return handle._duplicate().mapError { dupError in
|
||||
handle._duplicate().mapError { dupError in
|
||||
FileSystemError(
|
||||
message: "Unable to open directory stream for '\(handle.path)'.",
|
||||
wrapping: dupError
|
||||
@@ -443,7 +443,7 @@ private struct DirectoryEnumerator: Sendable {
|
||||
private mutating func makeFTSSource(
|
||||
_ handle: SystemFileHandle.SendableView
|
||||
) -> Result<Source, FileSystemError> {
|
||||
return Libc.ftsOpen(handle.path, options: [.noChangeDir, .physical]).mapError { errno in
|
||||
Libc.ftsOpen(handle.path, options: [.noChangeDir, .physical]).mapError { errno in
|
||||
FileSystemError.open("fts_open", error: errno, path: handle.path, location: .here())
|
||||
}.map {
|
||||
.fts($0)
|
||||
@@ -652,7 +652,7 @@ private struct DirectoryEnumerator: Sendable {
|
||||
|
||||
extension UnsafeMutablePointer<CInterop.FTSEnt> {
|
||||
fileprivate var path: FilePath {
|
||||
return FilePath(platformString: self.pointee.fts_path!)
|
||||
FilePath(platformString: self.pointee.fts_path!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public struct FileChunks: AsyncSequence {
|
||||
}
|
||||
|
||||
public func makeAsyncIterator() -> FileChunkIterator {
|
||||
return FileChunkIterator(wrapping: self.stream.makeAsyncIterator())
|
||||
FileChunkIterator(wrapping: self.stream.makeAsyncIterator())
|
||||
}
|
||||
|
||||
public struct FileChunkIterator: AsyncIteratorProtocol {
|
||||
@@ -161,7 +161,7 @@ private struct FileChunkProducer: Sendable {
|
||||
}
|
||||
|
||||
private func readNextChunk() throws -> ByteBuffer {
|
||||
return try self.state.withLockedValue { state in
|
||||
try self.state.withLockedValue { state in
|
||||
state.produceMore()
|
||||
}.flatMap {
|
||||
if let (descriptor, range) = $0 {
|
||||
|
||||
@@ -220,7 +220,7 @@ extension ReadableFileHandleProtocol {
|
||||
in range: ClosedRange<Int64>,
|
||||
chunkLength: ByteCount = .kibibytes(128)
|
||||
) -> FileChunks {
|
||||
return self.readChunks(in: Range(range), chunkLength: chunkLength)
|
||||
self.readChunks(in: Range(range), chunkLength: chunkLength)
|
||||
}
|
||||
|
||||
/// Returns an asynchronous sequence of chunks read from the file.
|
||||
@@ -235,7 +235,7 @@ extension ReadableFileHandleProtocol {
|
||||
in range: Range<Int64>,
|
||||
chunkLength: ByteCount = .kibibytes(128)
|
||||
) -> FileChunks {
|
||||
return self.readChunks(in: range, chunkLength: chunkLength)
|
||||
self.readChunks(in: range, chunkLength: chunkLength)
|
||||
}
|
||||
|
||||
/// Returns an asynchronous sequence of chunks read from the file.
|
||||
@@ -298,7 +298,7 @@ extension ReadableFileHandleProtocol {
|
||||
in range: UnboundedRange,
|
||||
chunkLength: ByteCount = .kibibytes(128)
|
||||
) -> FileChunks {
|
||||
return self.readChunks(in: 0..<Int64.max, chunkLength: chunkLength)
|
||||
self.readChunks(in: 0..<Int64.max, chunkLength: chunkLength)
|
||||
}
|
||||
|
||||
/// Returns an asynchronous sequence of chunks read from the file.
|
||||
@@ -312,7 +312,7 @@ extension ReadableFileHandleProtocol {
|
||||
public func readChunks(
|
||||
chunkLength: ByteCount = .kibibytes(128)
|
||||
) -> FileChunks {
|
||||
return self.readChunks(in: ..., chunkLength: chunkLength)
|
||||
self.readChunks(in: ..., chunkLength: chunkLength)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,7 +514,7 @@ extension WritableFileHandleProtocol {
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
extension FileHandleProtocol {
|
||||
/// Sets the file's last access time to the given time.
|
||||
///
|
||||
///
|
||||
/// - Parameter time: The time to which the file's last access time should be set.
|
||||
///
|
||||
/// - Throws: If there's an error updating the time. If this happens, the original value won't be modified.
|
||||
@@ -630,7 +630,7 @@ extension DirectoryFileHandleProtocol {
|
||||
/// The current (".") and parent ("..") directory entries are not included. The order of entries
|
||||
/// is arbitrary and should not be relied upon.
|
||||
public func listContents() -> DirectoryEntries {
|
||||
return self.listContents(recursive: false)
|
||||
self.listContents(recursive: false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -663,7 +663,7 @@ extension DirectoryFileHandleProtocol {
|
||||
let handle = try await self.openFile(forReadingAt: path, options: options)
|
||||
|
||||
return try await withUncancellableTearDown {
|
||||
return try await body(handle)
|
||||
try await body(handle)
|
||||
} tearDown: { _ in
|
||||
try await handle.close()
|
||||
}
|
||||
@@ -694,7 +694,7 @@ extension DirectoryFileHandleProtocol {
|
||||
let handle = try await self.openFile(forWritingAt: path, options: options)
|
||||
|
||||
return try await withUncancellableTearDown {
|
||||
return try await body(handle)
|
||||
try await body(handle)
|
||||
} tearDown: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
@@ -729,7 +729,7 @@ extension DirectoryFileHandleProtocol {
|
||||
let handle = try await self.openFile(forReadingAndWritingAt: path, options: options)
|
||||
|
||||
return try await withUncancellableTearDown {
|
||||
return try await body(handle)
|
||||
try await body(handle)
|
||||
} tearDown: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
@@ -755,7 +755,7 @@ extension DirectoryFileHandleProtocol {
|
||||
let handle = try await self.openDirectory(atPath: path, options: options)
|
||||
|
||||
return try await withUncancellableTearDown {
|
||||
return try await body(handle)
|
||||
try await body(handle)
|
||||
} tearDown: { _ in
|
||||
try await handle.close()
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public struct FileSystem: Sendable, FileSystemProtocol {
|
||||
let threadPool = NIOThreadPool(numberOfThreads: numberOfThreads)
|
||||
threadPool.start()
|
||||
// Wait for the thread pool to start.
|
||||
try? await threadPool.runIfActive { }
|
||||
try? await threadPool.runIfActive {}
|
||||
self.init(threadPool: threadPool, ownsThreadPool: true)
|
||||
}
|
||||
|
||||
@@ -263,7 +263,7 @@ public struct FileSystem: Sendable, FileSystemProtocol {
|
||||
public func createTemporaryDirectory(
|
||||
template: FilePath
|
||||
) async throws -> FilePath {
|
||||
return try await self.threadPool.runIfActive {
|
||||
try await self.threadPool.runIfActive {
|
||||
try self._createTemporaryDirectory(template: template).get()
|
||||
}
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public struct FileSystem: Sendable, FileSystemProtocol {
|
||||
forFileAt path: FilePath,
|
||||
infoAboutSymbolicLink: Bool
|
||||
) async throws -> FileInfo? {
|
||||
return try await self.threadPool.runIfActive {
|
||||
try await self.threadPool.runIfActive {
|
||||
try self._info(forFileAt: path, infoAboutSymbolicLink: infoAboutSymbolicLink).get()
|
||||
}
|
||||
}
|
||||
@@ -564,7 +564,7 @@ public struct FileSystem: Sendable, FileSystemProtocol {
|
||||
at linkPath: FilePath,
|
||||
withDestination destinationPath: FilePath
|
||||
) async throws {
|
||||
return try await self.threadPool.runIfActive {
|
||||
try await self.threadPool.runIfActive {
|
||||
try self._createSymbolicLink(at: linkPath, withDestination: destinationPath).get()
|
||||
}
|
||||
}
|
||||
@@ -595,7 +595,7 @@ public struct FileSystem: Sendable, FileSystemProtocol {
|
||||
public func destinationOfSymbolicLink(
|
||||
at path: FilePath
|
||||
) async throws -> FilePath {
|
||||
return try await self.threadPool.runIfActive {
|
||||
try await self.threadPool.runIfActive {
|
||||
try self._destinationOfSymbolicLink(at: path).get()
|
||||
}
|
||||
}
|
||||
@@ -632,7 +632,7 @@ public struct FileSystem: Sendable, FileSystemProtocol {
|
||||
get async throws {
|
||||
#if canImport(Darwin)
|
||||
return try await self.threadPool.runIfActive {
|
||||
return try Libc.constr(_CS_DARWIN_USER_TEMP_DIR).map { path in
|
||||
try Libc.constr(_CS_DARWIN_USER_TEMP_DIR).map { path in
|
||||
FilePath(path)
|
||||
}.mapError { errno in
|
||||
FileSystemError.confstr(
|
||||
@@ -694,7 +694,7 @@ extension NIOSingletons {
|
||||
extension FileSystemProtocol where Self == FileSystem {
|
||||
/// A global shared instance of ``FileSystem``.
|
||||
public static var shared: FileSystem {
|
||||
return FileSystem.shared
|
||||
FileSystem.shared
|
||||
}
|
||||
}
|
||||
|
||||
@@ -719,7 +719,7 @@ extension FileSystem {
|
||||
forReadingAt path: FilePath,
|
||||
options: OpenOptions.Read
|
||||
) -> Result<ReadFileHandle, FileSystemError> {
|
||||
return SystemFileHandle.syncOpen(
|
||||
SystemFileHandle.syncOpen(
|
||||
atPath: path,
|
||||
mode: .readOnly,
|
||||
options: options.descriptorOptions,
|
||||
@@ -736,7 +736,7 @@ extension FileSystem {
|
||||
forWritingAt path: FilePath,
|
||||
options: OpenOptions.Write
|
||||
) -> Result<WriteFileHandle, FileSystemError> {
|
||||
return SystemFileHandle.syncOpen(
|
||||
SystemFileHandle.syncOpen(
|
||||
atPath: path,
|
||||
mode: .writeOnly,
|
||||
options: options.descriptorOptions,
|
||||
@@ -753,7 +753,7 @@ extension FileSystem {
|
||||
forReadingAndWritingAt path: FilePath,
|
||||
options: OpenOptions.Write
|
||||
) -> Result<ReadWriteFileHandle, FileSystemError> {
|
||||
return SystemFileHandle.syncOpen(
|
||||
SystemFileHandle.syncOpen(
|
||||
atPath: path,
|
||||
mode: .readWrite,
|
||||
options: options.descriptorOptions,
|
||||
@@ -770,7 +770,7 @@ extension FileSystem {
|
||||
at path: FilePath,
|
||||
options: OpenOptions.Directory
|
||||
) -> Result<DirectoryFileHandle, FileSystemError> {
|
||||
return SystemFileHandle.syncOpen(
|
||||
SystemFileHandle.syncOpen(
|
||||
atPath: path,
|
||||
mode: .readOnly,
|
||||
options: options.descriptorOptions,
|
||||
@@ -1001,7 +1001,7 @@ extension FileSystem {
|
||||
path: FilePath,
|
||||
location: FileSystemError.SourceLocation
|
||||
) -> FileSystemError {
|
||||
return FileSystemError(
|
||||
FileSystemError(
|
||||
code: .closed,
|
||||
message: "Can't copy '\(sourcePath)' to '\(destinationPath)', '\(path)' is closed.",
|
||||
cause: nil,
|
||||
@@ -1354,7 +1354,7 @@ extension FileSystem {
|
||||
at linkPath: FilePath,
|
||||
withDestination destinationPath: FilePath
|
||||
) -> Result<Void, FileSystemError> {
|
||||
return Syscall.symlink(to: destinationPath, from: linkPath).mapError { errno in
|
||||
Syscall.symlink(to: destinationPath, from: linkPath).mapError { errno in
|
||||
FileSystemError.symlink(
|
||||
errno: errno,
|
||||
link: linkPath,
|
||||
|
||||
@@ -541,7 +541,7 @@ extension FileSystemError {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func fdopendir(errno: Errno, path: FilePath, location: SourceLocation) -> Self {
|
||||
return FileSystemError(
|
||||
FileSystemError(
|
||||
code: .unknown,
|
||||
message: "Unable to open directory stream for '\(path)'.",
|
||||
systemCall: "fdopendir",
|
||||
@@ -552,7 +552,7 @@ extension FileSystemError {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func readdir(errno: Errno, path: FilePath, location: SourceLocation) -> Self {
|
||||
return FileSystemError(
|
||||
FileSystemError(
|
||||
code: .unknown,
|
||||
message: "Unable to read directory stream for '\(path)'.",
|
||||
systemCall: "readdir",
|
||||
@@ -563,7 +563,7 @@ extension FileSystemError {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func ftsRead(errno: Errno, path: FilePath, location: SourceLocation) -> Self {
|
||||
return FileSystemError(
|
||||
FileSystemError(
|
||||
code: .unknown,
|
||||
message: "Unable to read FTS stream for '\(path)'.",
|
||||
systemCall: "fts_read",
|
||||
@@ -966,7 +966,7 @@ extension FileSystemError {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func getcwd(errno: Errno, location: SourceLocation) -> Self {
|
||||
return FileSystemError(
|
||||
FileSystemError(
|
||||
code: .unavailable,
|
||||
message: "Can't get current working directory.",
|
||||
systemCall: "getcwd",
|
||||
@@ -977,7 +977,7 @@ extension FileSystemError {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func confstr(name: String, errno: Errno, location: SourceLocation) -> Self {
|
||||
return FileSystemError(
|
||||
FileSystemError(
|
||||
code: .unavailable,
|
||||
message: "Can't get configuration value for '\(name)'.",
|
||||
systemCall: "confstr",
|
||||
@@ -1085,7 +1085,8 @@ extension FileSystemError {
|
||||
|
||||
case .readOnlyFileSystem:
|
||||
code = .unsupported
|
||||
message = "Not permitted to change last access or last data modification times for \(path): this is a read-only file system."
|
||||
message =
|
||||
"Not permitted to change last access or last data modification times for \(path): this is a read-only file system."
|
||||
|
||||
case .badFileDescriptor:
|
||||
code = .closed
|
||||
|
||||
@@ -118,7 +118,7 @@ extension FileSystemError {
|
||||
///
|
||||
/// - Returns: A multi-line description of the error.
|
||||
public func detailedDescription() -> String {
|
||||
return self.detailedDescriptionLines().joined(separator: "\n")
|
||||
self.detailedDescriptionLines().joined(separator: "\n")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,7 +256,7 @@ extension FileSystemError {
|
||||
file: String = #fileID,
|
||||
line: Int = #line
|
||||
) -> Self {
|
||||
return SourceLocation(function: function, file: file, line: line)
|
||||
SourceLocation(function: function, file: file, line: line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ extension FileSystemProtocol {
|
||||
) async throws -> Result {
|
||||
let handle = try await self.openFile(forReadingAt: path, options: options)
|
||||
return try await withUncancellableTearDown {
|
||||
return try await execute(handle)
|
||||
try await execute(handle)
|
||||
} tearDown: { _ in
|
||||
try await handle.close()
|
||||
}
|
||||
@@ -308,7 +308,7 @@ extension FileSystemProtocol {
|
||||
) async throws -> Result {
|
||||
let handle = try await self.openFile(forWritingAt: path, options: options)
|
||||
return try await withUncancellableTearDown {
|
||||
return try await execute(handle)
|
||||
try await execute(handle)
|
||||
} tearDown: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
@@ -340,7 +340,7 @@ extension FileSystemProtocol {
|
||||
) async throws -> Result {
|
||||
let handle = try await self.openFile(forReadingAndWritingAt: path, options: options)
|
||||
return try await withUncancellableTearDown {
|
||||
return try await execute(handle)
|
||||
try await execute(handle)
|
||||
} tearDown: { _ in
|
||||
try await handle.close()
|
||||
}
|
||||
@@ -361,7 +361,7 @@ extension FileSystemProtocol {
|
||||
) async throws -> Result {
|
||||
let handle = try await self.openDirectory(atPath: path, options: options)
|
||||
return try await withUncancellableTearDown {
|
||||
return try await execute(handle)
|
||||
try await execute(handle)
|
||||
} tearDown: { _ in
|
||||
try await handle.close()
|
||||
}
|
||||
@@ -406,7 +406,7 @@ extension FileSystemProtocol {
|
||||
/// - path: The path to get information about.
|
||||
/// - Returns: Information about the file at the given path or `nil` if no file exists.
|
||||
public func info(forFileAt path: FilePath) async throws -> FileInfo? {
|
||||
return try await self.info(forFileAt: path, infoAboutSymbolicLink: false)
|
||||
try await self.info(forFileAt: path, infoAboutSymbolicLink: false)
|
||||
}
|
||||
|
||||
/// Copies the item at the specified path to a new location.
|
||||
@@ -429,7 +429,7 @@ extension FileSystemProtocol {
|
||||
try await self.copyItem(at: sourcePath, to: destinationPath) { entry, error in
|
||||
throw error
|
||||
} shouldCopyFile: { source, destination in
|
||||
return true
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ internal struct AnyAsyncSequence<Element>: AsyncSequence {
|
||||
}
|
||||
|
||||
internal func makeAsyncIterator() -> AsyncIterator {
|
||||
return self._makeAsyncIterator()
|
||||
self._makeAsyncIterator()
|
||||
}
|
||||
|
||||
internal struct AsyncIterator: AsyncIteratorProtocol {
|
||||
@@ -85,7 +85,7 @@ internal struct AnyAsyncSequence<Element>: AsyncSequence {
|
||||
}
|
||||
|
||||
internal mutating func next() async throws -> Element? {
|
||||
return try await self.iterator.next() as? Element
|
||||
try await self.iterator.next() as? Element
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -527,12 +527,12 @@ extension BufferedStream {
|
||||
|
||||
func didYield(bufferDepth: Int) -> Bool {
|
||||
// We are demanding more until we reach the high watermark
|
||||
return bufferDepth < self._high
|
||||
bufferDepth < self._high
|
||||
}
|
||||
|
||||
func didConsume(bufferDepth: Int) -> Bool {
|
||||
// We start demanding again once we are below the low watermark
|
||||
return bufferDepth < self._low
|
||||
bufferDepth < self._low
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,7 +656,7 @@ extension BufferedStream {
|
||||
contentsOf sequence: some Sequence<Element>
|
||||
) throws -> Source.WriteResult {
|
||||
let action = self._stateMachine.withCriticalRegion {
|
||||
return $0.write(sequence)
|
||||
$0.write(sequence)
|
||||
}
|
||||
|
||||
switch action {
|
||||
@@ -781,8 +781,8 @@ extension BufferedStream {
|
||||
}
|
||||
|
||||
func suspendNext() async throws -> Element? {
|
||||
return try await withTaskCancellationHandler {
|
||||
return try await withCheckedThrowingContinuation { continuation in
|
||||
try await withTaskCancellationHandler {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
let action = self._stateMachine.withCriticalRegion {
|
||||
$0.suspendNext(continuation: continuation)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public func withUncancellableTearDown<R>(
|
||||
result = .failure(error)
|
||||
}
|
||||
|
||||
let errorOnlyResult: Result<Void, Error> = result.map { _ in return () }
|
||||
let errorOnlyResult: Result<Void, Error> = result.map { _ in () }
|
||||
let tearDownResult: Result<Void, Error> = try await withoutCancellation {
|
||||
do {
|
||||
return .success(try await tearDown(errorOnlyResult))
|
||||
|
||||
@@ -89,7 +89,7 @@ public func nothingOrErrno<I: FixedWidthInteger>(
|
||||
retryOnInterrupt: Bool = true,
|
||||
_ fn: () -> I
|
||||
) -> Result<Void, Errno> {
|
||||
return valueOrErrno(retryOnInterrupt: retryOnInterrupt, fn).map { _ in }
|
||||
valueOrErrno(retryOnInterrupt: retryOnInterrupt, fn).map { _ in }
|
||||
}
|
||||
|
||||
/// Returns a `Result` representing the value returned from the given closure
|
||||
|
||||
@@ -108,7 +108,7 @@ extension FileDescriptor {
|
||||
public func listExtendedAttributes(
|
||||
_ buffer: UnsafeMutableBufferPointer<CChar>?
|
||||
) -> Result<Int, Errno> {
|
||||
return valueOrErrno(retryOnInterrupt: false) {
|
||||
valueOrErrno(retryOnInterrupt: false) {
|
||||
system_flistxattr(self.rawValue, buffer?.baseAddress, buffer?.count ?? 0)
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ extension FileDescriptor {
|
||||
named name: String,
|
||||
buffer: UnsafeMutableRawBufferPointer?
|
||||
) -> Result<Int, Errno> {
|
||||
return valueOrErrno(retryOnInterrupt: false) {
|
||||
valueOrErrno(retryOnInterrupt: false) {
|
||||
name.withPlatformString {
|
||||
system_fgetxattr(self.rawValue, $0, buffer?.baseAddress, buffer?.count ?? 0)
|
||||
}
|
||||
@@ -198,7 +198,7 @@ extension FileDescriptor {
|
||||
extension FileDescriptor {
|
||||
func listExtendedAttributes() -> Result<[String], Errno> {
|
||||
// Required capacity is returned if a no buffer is passed to flistxattr.
|
||||
return self.listExtendedAttributes(nil).flatMap { capacity in
|
||||
self.listExtendedAttributes(nil).flatMap { capacity in
|
||||
guard capacity > 0 else {
|
||||
// Required capacity is zero: no attributes to read.
|
||||
return .success([])
|
||||
@@ -226,7 +226,7 @@ extension FileDescriptor {
|
||||
|
||||
func readExtendedAttribute(named name: String) -> Result<[UInt8], Errno> {
|
||||
// Required capacity is returned if a no buffer is passed to fgetxattr.
|
||||
return self.getExtendedAttribute(named: name, buffer: nil).flatMap { capacity in
|
||||
self.getExtendedAttribute(named: name, buffer: nil).flatMap { capacity in
|
||||
guard capacity > 0 else {
|
||||
// Required capacity is zero: no values to read.
|
||||
return .success([])
|
||||
@@ -263,7 +263,7 @@ extension FileDescriptor {
|
||||
// factor here. However we should investigate whether it's possible to have a pool of
|
||||
// buffers which we can reuse. This would need to be at least as large as the high watermark
|
||||
// of the chunked file for it to be useful.
|
||||
return Result {
|
||||
Result {
|
||||
var buffer = ByteBuffer()
|
||||
try buffer.writeWithUnsafeMutableBytes(minimumWritableBytes: Int(length)) { buffer in
|
||||
let bufferPointer: UnsafeMutableRawBufferPointer
|
||||
@@ -295,7 +295,7 @@ extension FileDescriptor {
|
||||
contentsOf bytes: some Sequence<UInt8>,
|
||||
toAbsoluteOffset offset: Int64
|
||||
) -> Result<Int64, Error> {
|
||||
return Result {
|
||||
Result {
|
||||
Int64(try self.writeAll(toAbsoluteOffset: offset, bytes))
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ extension FileDescriptor {
|
||||
func write(
|
||||
contentsOf bytes: some Sequence<UInt8>
|
||||
) -> Result<Int64, Error> {
|
||||
return Result {
|
||||
Result {
|
||||
Int64(try self.writeAll(bytes))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,10 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/*
|
||||
This source file is part of the Swift System open source project
|
||||
|
||||
Copyright (c) 2020 Apple Inc. and the Swift System project authors
|
||||
Licensed under Apache License v2.0 with Runtime Library Exception
|
||||
|
||||
See https://swift.org/LICENSE.txt for license information
|
||||
*/
|
||||
// This source file is part of the Swift System open source project//
|
||||
// Copyright (c) 2020 Apple Inc. and the Swift System project authors
|
||||
// Licensed under Apache License v2.0 with Runtime Library Exception//
|
||||
// See https://swift.org/LICENSE.txt for license information
|
||||
|
||||
#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS) || os(Linux) || os(Android)
|
||||
import SystemPackage
|
||||
@@ -141,7 +137,7 @@ extension MockingDriver {
|
||||
// Check TLS for mocking
|
||||
@inline(never)
|
||||
private var contextualMockingEnabled: Bool {
|
||||
return currentMockingDriver != nil
|
||||
currentMockingDriver != nil
|
||||
}
|
||||
|
||||
extension MockingDriver {
|
||||
@@ -212,7 +208,7 @@ private func mockImpl(syscall name: String, args: [AnyHashable]) -> CInt {
|
||||
}
|
||||
|
||||
private func reinterpret(_ args: [AnyHashable?]) -> [AnyHashable] {
|
||||
return args.map { arg in
|
||||
args.map { arg in
|
||||
switch arg {
|
||||
case let charPointer as UnsafePointer<CInterop.PlatformChar>:
|
||||
return String(_errorCorrectingPlatformString: charPointer)
|
||||
@@ -234,14 +230,14 @@ func mock(
|
||||
syscall name: String = #function,
|
||||
_ args: AnyHashable?...
|
||||
) -> CInt {
|
||||
return mockImpl(syscall: name, args: reinterpret(args))
|
||||
mockImpl(syscall: name, args: reinterpret(args))
|
||||
}
|
||||
|
||||
func mockInt(
|
||||
syscall name: String = #function,
|
||||
_ args: AnyHashable?...
|
||||
) -> Int {
|
||||
return Int(mockImpl(syscall: name, args: reinterpret(args)))
|
||||
Int(mockImpl(syscall: name, args: reinterpret(args)))
|
||||
}
|
||||
|
||||
#endif // ENABLE_MOCKING
|
||||
@@ -312,7 +308,7 @@ internal func system_strlen(_ s: UnsafeMutablePointer<CChar>) -> Int {
|
||||
|
||||
// strlen for the platform string
|
||||
internal func system_platform_strlen(_ s: UnsafePointer<CInterop.PlatformChar>) -> Int {
|
||||
return strlen(s)
|
||||
strlen(s)
|
||||
}
|
||||
|
||||
// memset for raw buffers
|
||||
@@ -331,7 +327,7 @@ extension String {
|
||||
_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result
|
||||
) rethrows -> Result {
|
||||
// Need to #if because CChar may be signed
|
||||
return try withCString(body)
|
||||
try withCString(body)
|
||||
}
|
||||
|
||||
internal init?(_platformString platformString: UnsafePointer<CInterop.PlatformChar>) {
|
||||
@@ -364,6 +360,6 @@ internal func setTLS(_ key: _PlatformTLSKey, _ p: UnsafeMutableRawPointer?) {
|
||||
}
|
||||
|
||||
internal func getTLS(_ key: _PlatformTLSKey) -> UnsafeMutableRawPointer? {
|
||||
return pthread_getspecific(key)
|
||||
pthread_getspecific(key)
|
||||
}
|
||||
#endif
|
||||
@@ -30,7 +30,7 @@ import CNIOLinux
|
||||
public enum Syscall {
|
||||
@_spi(Testing)
|
||||
public static func stat(path: FilePath) -> Result<CInterop.Stat, Errno> {
|
||||
return path.withPlatformString { platformPath in
|
||||
path.withPlatformString { platformPath in
|
||||
var status = CInterop.Stat()
|
||||
return valueOrErrno(retryOnInterrupt: false) {
|
||||
system_stat(platformPath, &status)
|
||||
@@ -42,7 +42,7 @@ public enum Syscall {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func lstat(path: FilePath) -> Result<CInterop.Stat, Errno> {
|
||||
return path.withPlatformString { platformPath in
|
||||
path.withPlatformString { platformPath in
|
||||
var status = CInterop.Stat()
|
||||
return valueOrErrno(retryOnInterrupt: false) {
|
||||
system_lstat(platformPath, &status)
|
||||
@@ -54,7 +54,7 @@ public enum Syscall {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func mkdir(at path: FilePath, permissions: FilePermissions) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
path.withPlatformString { p in
|
||||
system_mkdir(p, permissions.rawValue)
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public enum Syscall {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func rename(from old: FilePath, to new: FilePath) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
old.withPlatformString { oldPath in
|
||||
new.withPlatformString { newPath in
|
||||
system_rename(oldPath, newPath)
|
||||
@@ -79,7 +79,7 @@ public enum Syscall {
|
||||
to new: FilePath,
|
||||
options: RenameOptions
|
||||
) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
old.withPlatformString { oldPath in
|
||||
new.withPlatformString { newPath in
|
||||
system_renamex_np(oldPath, newPath, options.rawValue)
|
||||
@@ -97,11 +97,11 @@ public enum Syscall {
|
||||
}
|
||||
|
||||
public static var exclusive: Self {
|
||||
return Self(rawValue: UInt32(bitPattern: RENAME_EXCL))
|
||||
Self(rawValue: UInt32(bitPattern: RENAME_EXCL))
|
||||
}
|
||||
|
||||
public static var swap: Self {
|
||||
return Self(rawValue: UInt32(bitPattern: RENAME_SWAP))
|
||||
Self(rawValue: UInt32(bitPattern: RENAME_SWAP))
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -115,7 +115,7 @@ public enum Syscall {
|
||||
relativeTo newFD: FileDescriptor,
|
||||
flags: RenameAtFlags
|
||||
) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
old.withPlatformString { oldPath in
|
||||
new.withPlatformString { newPath in
|
||||
system_renameat2(
|
||||
@@ -139,11 +139,11 @@ public enum Syscall {
|
||||
}
|
||||
|
||||
public static var exclusive: Self {
|
||||
return Self(rawValue: CNIOLinux_RENAME_NOREPLACE)
|
||||
Self(rawValue: CNIOLinux_RENAME_NOREPLACE)
|
||||
}
|
||||
|
||||
public static var swap: Self {
|
||||
return Self(rawValue: CNIOLinux_RENAME_EXCHANGE)
|
||||
Self(rawValue: CNIOLinux_RENAME_EXCHANGE)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -178,7 +178,7 @@ public enum Syscall {
|
||||
relativeTo destinationFD: FileDescriptor,
|
||||
flags: LinkAtFlags
|
||||
) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
source.withPlatformString { src in
|
||||
destination.withPlatformString { dst in
|
||||
system_linkat(
|
||||
@@ -199,7 +199,7 @@ public enum Syscall {
|
||||
from source: FilePath,
|
||||
to destination: FilePath
|
||||
) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
source.withPlatformString { src in
|
||||
destination.withPlatformString { dst in
|
||||
system_link(src, dst)
|
||||
@@ -210,7 +210,7 @@ public enum Syscall {
|
||||
|
||||
@_spi(Testing)
|
||||
public static func unlink(path: FilePath) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
path.withPlatformString { ptr in
|
||||
system_unlink(ptr)
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public enum Syscall {
|
||||
to destination: FilePath,
|
||||
from source: FilePath
|
||||
) -> Result<Void, Errno> {
|
||||
return nothingOrErrno(retryOnInterrupt: false) {
|
||||
nothingOrErrno(retryOnInterrupt: false) {
|
||||
source.withPlatformString { src in
|
||||
destination.withPlatformString { dst in
|
||||
system_symlink(dst, src)
|
||||
@@ -381,7 +381,10 @@ public enum Libc {
|
||||
pathBytes.withUnsafeMutableBufferPointer { pointer in
|
||||
// The array must be terminated with a nil.
|
||||
#if os(Android)
|
||||
libc_fts_open([pointer.baseAddress!, unsafeBitCast(0, to: UnsafeMutablePointer<CInterop.PlatformChar>.self)], options.rawValue)
|
||||
libc_fts_open(
|
||||
[pointer.baseAddress!, unsafeBitCast(0, to: UnsafeMutablePointer<CInterop.PlatformChar>.self)],
|
||||
options.rawValue
|
||||
)
|
||||
#else
|
||||
libc_fts_open([pointer.baseAddress, nil], options.rawValue)
|
||||
#endif
|
||||
|
||||
@@ -367,21 +367,21 @@ internal func system_futimens(
|
||||
internal func libc_fdopendir(
|
||||
_ fd: FileDescriptor.RawValue
|
||||
) -> CInterop.DirPointer {
|
||||
return fdopendir(fd)!
|
||||
fdopendir(fd)!
|
||||
}
|
||||
|
||||
/// readdir(3): Returns a pointer to the next directory entry
|
||||
internal func libc_readdir(
|
||||
_ dir: CInterop.DirPointer
|
||||
) -> UnsafeMutablePointer<CInterop.DirEnt>? {
|
||||
return readdir(dir)
|
||||
readdir(dir)
|
||||
}
|
||||
|
||||
/// readdir(3): Closes the directory stream and frees associated structures
|
||||
internal func libc_closedir(
|
||||
_ dir: CInterop.DirPointer
|
||||
) -> CInt {
|
||||
return closedir(dir)
|
||||
closedir(dir)
|
||||
}
|
||||
|
||||
/// remove(3): Remove directory entry
|
||||
@@ -418,7 +418,7 @@ internal func libc_getcwd(
|
||||
_ buffer: UnsafeMutablePointer<CInterop.PlatformChar>,
|
||||
_ size: Int
|
||||
) -> UnsafeMutablePointer<CInterop.PlatformChar>? {
|
||||
return getcwd(buffer, size)
|
||||
getcwd(buffer, size)
|
||||
}
|
||||
|
||||
/// confstr(3)
|
||||
@@ -428,7 +428,7 @@ internal func libc_confstr(
|
||||
_ buffer: UnsafeMutablePointer<CInterop.PlatformChar>,
|
||||
_ size: Int
|
||||
) -> Int {
|
||||
return confstr(name, buffer, size)
|
||||
confstr(name, buffer, size)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -438,14 +438,14 @@ internal func libc_fts_open(
|
||||
_ path: [UnsafeMutablePointer<CInterop.PlatformChar>],
|
||||
_ options: CInt
|
||||
) -> UnsafeMutablePointer<CInterop.FTS> {
|
||||
return fts_open(path, options, nil)!
|
||||
fts_open(path, options, nil)!
|
||||
}
|
||||
#else
|
||||
internal func libc_fts_open(
|
||||
_ path: [UnsafeMutablePointer<CInterop.PlatformChar>?],
|
||||
_ options: CInt
|
||||
) -> UnsafeMutablePointer<CInterop.FTS> {
|
||||
return fts_open(path, options, nil)
|
||||
fts_open(path, options, nil)
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -453,13 +453,13 @@ internal func libc_fts_open(
|
||||
internal func libc_fts_read(
|
||||
_ fts: UnsafeMutablePointer<CInterop.FTS>
|
||||
) -> UnsafeMutablePointer<CInterop.FTSEnt>? {
|
||||
return fts_read(fts)
|
||||
fts_read(fts)
|
||||
}
|
||||
|
||||
/// fts(3)
|
||||
internal func libc_fts_close(
|
||||
_ fts: UnsafeMutablePointer<CInterop.FTS>
|
||||
) -> CInt {
|
||||
return fts_close(fts)
|
||||
fts_close(fts)
|
||||
}
|
||||
#endif
|
||||
@@ -145,7 +145,7 @@ public final class SystemFileHandle {
|
||||
extension SystemFileHandle.SendableView {
|
||||
/// Returns the file descriptor if it's available; `nil` otherwise.
|
||||
internal func descriptorIfAvailable() -> FileDescriptor? {
|
||||
return self.lifecycle.withLockedValue {
|
||||
self.lifecycle.withLockedValue {
|
||||
switch $0 {
|
||||
case let .open(descriptor):
|
||||
return descriptor
|
||||
@@ -196,37 +196,37 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
// currently using.
|
||||
|
||||
public func info() async throws -> FileInfo {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._info().get()
|
||||
}
|
||||
}
|
||||
|
||||
public func replacePermissions(_ permissions: FilePermissions) async throws {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._replacePermissions(permissions)
|
||||
}
|
||||
}
|
||||
|
||||
public func addPermissions(_ permissions: FilePermissions) async throws -> FilePermissions {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._addPermissions(permissions)
|
||||
}
|
||||
}
|
||||
|
||||
public func removePermissions(_ permissions: FilePermissions) async throws -> FilePermissions {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._removePermissions(permissions)
|
||||
}
|
||||
}
|
||||
|
||||
public func attributeNames() async throws -> [String] {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._attributeNames()
|
||||
}
|
||||
}
|
||||
|
||||
public func valueForAttribute(_ name: String) async throws -> [UInt8] {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._valueForAttribute(name)
|
||||
}
|
||||
}
|
||||
@@ -235,19 +235,19 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
_ bytes: some (Sendable & RandomAccessCollection<UInt8>),
|
||||
attribute name: String
|
||||
) async throws {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._updateValueForAttribute(bytes, attribute: name)
|
||||
}
|
||||
}
|
||||
|
||||
public func removeValueForAttribute(_ name: String) async throws {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._removeValueForAttribute(name)
|
||||
}
|
||||
}
|
||||
|
||||
public func synchronize() async throws {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._synchronize()
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,7 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
) async throws -> R {
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._withUnsafeDescriptor {
|
||||
return try execute($0)
|
||||
try execute($0)
|
||||
} onUnavailable: {
|
||||
FileSystemError(
|
||||
code: .closed,
|
||||
@@ -270,7 +270,7 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
}
|
||||
|
||||
public func detachUnsafeFileDescriptor() throws -> FileDescriptor {
|
||||
return try self.sendableView.lifecycle.withLockedValue { lifecycle in
|
||||
try self.sendableView.lifecycle.withLockedValue { lifecycle in
|
||||
switch lifecycle {
|
||||
case let .open(descriptor):
|
||||
lifecycle = .detached
|
||||
@@ -377,18 +377,18 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
extension SystemFileHandle.SendableView {
|
||||
/// Returns a string in the format: "{message}, the file '{path}' is closed."
|
||||
private func fileIsClosed(_ message: String) -> String {
|
||||
return "\(message), the file '\(self.path)' is closed."
|
||||
"\(message), the file '\(self.path)' is closed."
|
||||
}
|
||||
|
||||
/// Returns a string in the format: "{message} for '{path}'."
|
||||
private func unknown(_ message: String) -> String {
|
||||
return "\(message) for '\(self.path)'."
|
||||
"\(message) for '\(self.path)'."
|
||||
}
|
||||
|
||||
@_spi(Testing)
|
||||
public func _info() -> Result<FileInfo, FileSystemError> {
|
||||
self._withUnsafeDescriptorResult { descriptor in
|
||||
return descriptor.status().map { stat in
|
||||
descriptor.status().map { stat in
|
||||
FileInfo(platformSpecificStatus: stat)
|
||||
}.mapError { errno in
|
||||
.stat("fstat", errno: errno, path: self.path, location: .here())
|
||||
@@ -507,7 +507,7 @@ extension SystemFileHandle.SendableView {
|
||||
operand: FilePermissions,
|
||||
descriptor: FileDescriptor
|
||||
) throws {
|
||||
return try descriptor.changeMode(permissions).mapError { errno in
|
||||
try descriptor.changeMode(permissions).mapError { errno in
|
||||
FileSystemError.fchmod(
|
||||
operation: operation,
|
||||
operand: operand,
|
||||
@@ -521,8 +521,8 @@ extension SystemFileHandle.SendableView {
|
||||
|
||||
@_spi(Testing)
|
||||
public func _attributeNames() throws -> [String] {
|
||||
return try self._withUnsafeDescriptor { descriptor in
|
||||
return try descriptor.listExtendedAttributes().mapError { errno in
|
||||
try self._withUnsafeDescriptor { descriptor in
|
||||
try descriptor.listExtendedAttributes().mapError { errno in
|
||||
FileSystemError.flistxattr(errno: errno, path: self.path, location: .here())
|
||||
}.get()
|
||||
} onUnavailable: {
|
||||
@@ -537,8 +537,8 @@ extension SystemFileHandle.SendableView {
|
||||
|
||||
@_spi(Testing)
|
||||
public func _valueForAttribute(_ name: String) throws -> [UInt8] {
|
||||
return try self._withUnsafeDescriptor { descriptor in
|
||||
return try descriptor.readExtendedAttribute(
|
||||
try self._withUnsafeDescriptor { descriptor in
|
||||
try descriptor.readExtendedAttribute(
|
||||
named: name
|
||||
).flatMapError { errno -> Result<[UInt8], FileSystemError> in
|
||||
switch errno {
|
||||
@@ -577,7 +577,7 @@ extension SystemFileHandle.SendableView {
|
||||
_ bytes: some RandomAccessCollection<UInt8>,
|
||||
attribute name: String
|
||||
) throws {
|
||||
return try self._withUnsafeDescriptor { descriptor in
|
||||
try self._withUnsafeDescriptor { descriptor in
|
||||
func withUnsafeBufferPointer(_ body: (UnsafeBufferPointer<UInt8>) throws -> Void) throws {
|
||||
try bytes.withContiguousStorageIfAvailable(body)
|
||||
?? Array(bytes).withUnsafeBufferPointer(body)
|
||||
@@ -611,7 +611,7 @@ extension SystemFileHandle.SendableView {
|
||||
|
||||
@_spi(Testing)
|
||||
public func _removeValueForAttribute(_ name: String) throws {
|
||||
return try self._withUnsafeDescriptor { descriptor in
|
||||
try self._withUnsafeDescriptor { descriptor in
|
||||
try descriptor.removeExtendedAttribute(name).mapError { errno in
|
||||
FileSystemError.fremovexattr(
|
||||
attribute: name,
|
||||
@@ -647,7 +647,7 @@ extension SystemFileHandle.SendableView {
|
||||
}
|
||||
|
||||
internal func _duplicate() -> Result<FileDescriptor, FileSystemError> {
|
||||
return self._withUnsafeDescriptorResult { descriptor in
|
||||
self._withUnsafeDescriptorResult { descriptor in
|
||||
Result {
|
||||
try descriptor.duplicate()
|
||||
}.mapError { error in
|
||||
@@ -680,7 +680,11 @@ extension SystemFileHandle.SendableView {
|
||||
}
|
||||
|
||||
// Materialize then close.
|
||||
let materializeResult = self._materialize(materialize, descriptor: descriptor, failRenameat2WithEINVAL: failRenameat2WithEINVAL)
|
||||
let materializeResult = self._materialize(
|
||||
materialize,
|
||||
descriptor: descriptor,
|
||||
failRenameat2WithEINVAL: failRenameat2WithEINVAL
|
||||
)
|
||||
|
||||
return Result {
|
||||
try descriptor.close()
|
||||
@@ -760,7 +764,7 @@ extension SystemFileHandle.SendableView {
|
||||
location: .here()
|
||||
)
|
||||
}.flatMap {
|
||||
return linkAtProcFS().mapError { errno in
|
||||
linkAtProcFS().mapError { errno in
|
||||
FileSystemError.link(
|
||||
errno: errno,
|
||||
from: createdPath,
|
||||
@@ -1019,8 +1023,8 @@ extension SystemFileHandle: ReadableFileHandleProtocol {
|
||||
fromAbsoluteOffset offset: Int64,
|
||||
length: ByteCount
|
||||
) async throws -> ByteBuffer {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
return try sendableView._withUnsafeDescriptor { descriptor in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._withUnsafeDescriptor { descriptor in
|
||||
try descriptor.readChunk(
|
||||
fromAbsoluteOffset: offset,
|
||||
length: length.bytes
|
||||
@@ -1072,7 +1076,7 @@ extension SystemFileHandle: ReadableFileHandleProtocol {
|
||||
in range: Range<Int64>,
|
||||
chunkLength size: ByteCount
|
||||
) -> FileChunks {
|
||||
return FileChunks(handle: self, chunkLength: size, range: range)
|
||||
FileChunks(handle: self, chunkLength: size, range: range)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1085,8 +1089,8 @@ extension SystemFileHandle: WritableFileHandleProtocol {
|
||||
contentsOf bytes: some (Sequence<UInt8> & Sendable),
|
||||
toAbsoluteOffset offset: Int64
|
||||
) async throws -> Int64 {
|
||||
return try await self.threadPool.runIfActive { [sendableView] in
|
||||
return try sendableView._withUnsafeDescriptor { descriptor in
|
||||
try await self.threadPool.runIfActive { [sendableView] in
|
||||
try sendableView._withUnsafeDescriptor { descriptor in
|
||||
try descriptor.write(contentsOf: bytes, toAbsoluteOffset: offset)
|
||||
.flatMapError { error in
|
||||
if let errno = error as? Errno, errno == .illegalSeek {
|
||||
@@ -1143,7 +1147,7 @@ extension SystemFileHandle: WritableFileHandleProtocol {
|
||||
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
|
||||
extension SystemFileHandle.SendableView {
|
||||
func _resize(to size: ByteCount) -> Result<(), FileSystemError> {
|
||||
return self._withUnsafeDescriptorResult { descriptor in
|
||||
self._withUnsafeDescriptorResult { descriptor in
|
||||
Result {
|
||||
try descriptor.resize(to: size.bytes, retryOnInterrupt: true)
|
||||
}.mapError { error in
|
||||
@@ -1169,7 +1173,7 @@ extension SystemFileHandle: DirectoryFileHandleProtocol {
|
||||
public typealias ReadWriteFileHandle = SystemFileHandle
|
||||
|
||||
public func listContents(recursive: Bool) -> DirectoryEntries {
|
||||
return DirectoryEntries(handle: self, recursive: recursive)
|
||||
DirectoryEntries(handle: self, recursive: recursive)
|
||||
}
|
||||
|
||||
public func openFile(
|
||||
@@ -1370,7 +1374,7 @@ extension SystemFileHandle {
|
||||
permissions: FilePermissions?,
|
||||
threadPool: NIOThreadPool
|
||||
) -> Result<SystemFileHandle, FileSystemError> {
|
||||
return Result {
|
||||
Result {
|
||||
try FileDescriptor.open(
|
||||
path,
|
||||
mode,
|
||||
@@ -1512,7 +1516,7 @@ extension SystemFileHandle {
|
||||
|
||||
return .success(handle)
|
||||
} catch {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
// 'O_TMPFILE' isn't supported for the current file system, try again but using
|
||||
// rename instead.
|
||||
if useTemporaryFileIfPossible, let errno = error as? Errno, errno == .notSupported {
|
||||
|
||||
@@ -124,7 +124,7 @@ public enum OpenOptions {
|
||||
replaceExisting: Bool,
|
||||
permissions: FilePermissions? = nil
|
||||
) -> Self {
|
||||
return Write(
|
||||
Write(
|
||||
existingFile: replaceExisting ? .truncate : .none,
|
||||
newFile: NewFile(permissions: permissions)
|
||||
)
|
||||
@@ -143,7 +143,7 @@ public enum OpenOptions {
|
||||
createIfNecessary: Bool,
|
||||
permissions: FilePermissions? = nil
|
||||
) -> Self {
|
||||
return Write(
|
||||
Write(
|
||||
existingFile: .open,
|
||||
newFile: createIfNecessary ? NewFile(permissions: permissions) : nil
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user