mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +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
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user