Fix tests on Linux
This commit is contained in:
@@ -47,7 +47,7 @@ public extension Data {
|
||||
func write(to: Path, atomically: Bool = false) throws -> Path {
|
||||
let opts: NSData.WritingOptions
|
||||
if atomically {
|
||||
#if os(macOS)
|
||||
#if !os(Linux)
|
||||
opts = .atomicWrite
|
||||
#else
|
||||
opts = .atomic
|
||||
|
||||
@@ -73,24 +73,37 @@ public extension Path {
|
||||
return try "".write(to: self)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@discardableResult
|
||||
public func mkdir() throws -> Path {
|
||||
private func _foo(go: () throws -> Void) throws {
|
||||
#if !os(Linux)
|
||||
do {
|
||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: false, attributes: nil)
|
||||
try go()
|
||||
} catch CocoaError.Code.fileWriteFileExists {
|
||||
// noop
|
||||
}
|
||||
#else
|
||||
do {
|
||||
try go()
|
||||
} catch {
|
||||
let error = error as NSError
|
||||
guard error.domain == NSCocoaErrorDomain, error.code == CocoaError.Code.fileWriteFileExists.rawValue else {
|
||||
throw error
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
public func mkdir() throws -> Path {
|
||||
try _foo {
|
||||
try FileManager.default.createDirectory(at: self.url, withIntermediateDirectories: false, attributes: nil)
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
@inlinable
|
||||
@discardableResult
|
||||
public func mkpath() throws -> Path {
|
||||
do {
|
||||
try _foo {
|
||||
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
|
||||
} catch CocoaError.Code.fileWriteFileExists {
|
||||
// noop
|
||||
}
|
||||
return self
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ public class TemporaryDirectory {
|
||||
public var path: Path { return Path(string: url.path) }
|
||||
|
||||
public init() throws {
|
||||
#if os(macOS)
|
||||
#if !os(Linux)
|
||||
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true)
|
||||
#else
|
||||
let envs = ProcessInfo.processInfo.environment
|
||||
|
||||
Reference in New Issue
Block a user