Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions Sources/SWBUtil/POSIX.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ import SWBLibc

public import protocol Foundation.LocalizedError

#if os(Windows)
#if canImport(System)
import System
public import System
#else
import SystemPackage
#endif
public import SystemPackage
#endif

public enum POSIX: Sendable {
Expand Down Expand Up @@ -78,12 +76,16 @@ public enum POSIX: Sendable {
}

public struct POSIXError: Error, LocalizedError, CustomStringConvertible, Equatable {
public let code: Int32
public let underlyingError: Errno
public let context: String?
public let arguments: [String]

public var code: Int32 {
underlyingError.rawValue
}

public init(_ code: Int32, context: String? = nil, _ arguments: [String]) {
self.code = code
self.underlyingError = Errno(rawValue: code)
self.context = context
self.arguments = arguments
}
Expand All @@ -93,7 +95,7 @@ public struct POSIXError: Error, LocalizedError, CustomStringConvertible, Equata
}

public var description: String {
let end = "\(String(cString: strerror(code))) (\(code))"
let end = "\(underlyingError.description) (\(code))"
if let context {
return "\(context)(\(arguments.joined(separator: ", "))): \(end)"
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/SWBUtil/PbxCp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ fileprivate func copyTree(_ srcPath: Path, _ dstPath: Path, options: CopyOptions
do {
_srcPath = try localFS.realpath(srcPath)
} catch let error as POSIXError {
outStream <<< "error: \(srcPath.str): \(String(cString: strerror(error.code)))\n"
// TODO: Does this really need to print specially for POSIXError?
outStream <<< "error: \(srcPath.str): \(error.underlyingError.description)\n"
return false
} catch {
outStream <<< "error: \(srcPath.str): \(error.localizedDescription)\n"
Expand All @@ -441,7 +442,8 @@ fileprivate func copyTree(_ srcPath: Path, _ dstPath: Path, options: CopyOptions
do {
_dstPath = try localFS.realpath(dstPath)
} catch let error as POSIXError {
outStream <<< "error: \(dstPath.str): \(String(cString: strerror(error.code)))\n"
// TODO: Does this really need to print specially for POSIXError?
outStream <<< "error: \(dstPath.str): \(error.underlyingError.description)\n"
return false
} catch {
outStream <<< "error: \(srcPath.str): \(error.localizedDescription)\n"
Expand Down
Loading