From cac06d89fb9cf72996702ea45dd5d36dbc0b7dd2 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 17 Jan 2019 17:31:29 -0500 Subject: [PATCH] Linux --- .travis.yml | 16 ++++++++++++++++ Sources/Extensions.swift | 4 ++++ Sources/TemporaryDirectory.swift | 9 +++++++++ 3 files changed, 29 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3e86dd0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +# only run for: merge commits, releases and pull-requests +if: type != push OR branch = master OR branch =~ /^\d+\.\d+(\.\d+)?(-\S*)?$/ + +jobs: + include: + - os: osx + language: swift + osx_image: xcode10.1 + script: swift test + - env: SWIFT_VERSION=4.2.1 + os: linux + language: generic + dist: trusty + sudo: false + install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)" + script: swift test diff --git a/Sources/Extensions.swift b/Sources/Extensions.swift index 475bb77..1670c49 100644 --- a/Sources/Extensions.swift +++ b/Sources/Extensions.swift @@ -47,7 +47,11 @@ public extension Data { func write(to: Path, atomically: Bool = false) throws -> Path { let opts: NSData.WritingOptions if atomically { + #if os(macOS) opts = .atomicWrite + #else + opts = .atomic + #endif } else { opts = [] } diff --git a/Sources/TemporaryDirectory.swift b/Sources/TemporaryDirectory.swift index 0c31171..ecacc3e 100644 --- a/Sources/TemporaryDirectory.swift +++ b/Sources/TemporaryDirectory.swift @@ -5,7 +5,16 @@ public class TemporaryDirectory { public var path: Path { return Path(string: url.path) } public init() throws { + #if os(macOS) url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true) + #else + let envs = ProcessInfo.processInfo.environment + let env = envs["TMPDIR"] ?? envs["TEMP"] ?? envs["TMP"] ?? "/tmp" + let dir = Path.root/env/"swift-sh.XXXXXX" + var template = [UInt8](dir.string.utf8).map({ Int8($0) }) + [Int8(0)] + guard mkdtemp(&template) != nil else { throw CocoaError.error(.featureUnsupported) } + url = URL(fileURLWithPath: String(cString: template)) + #endif } deinit {