This commit is contained in:
Max Howell
2019-01-17 17:31:29 -05:00
parent 4af0ee3983
commit cac06d89fb
3 changed files with 29 additions and 0 deletions

16
.travis.yml Normal file
View File

@@ -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

View File

@@ -47,7 +47,11 @@ public extension Data {
func write(to: Path, atomically: Bool = false) throws -> Path { func write(to: Path, atomically: Bool = false) throws -> Path {
let opts: NSData.WritingOptions let opts: NSData.WritingOptions
if atomically { if atomically {
#if os(macOS)
opts = .atomicWrite opts = .atomicWrite
#else
opts = .atomic
#endif
} else { } else {
opts = [] opts = []
} }

View File

@@ -5,7 +5,16 @@ public class TemporaryDirectory {
public var path: Path { return Path(string: url.path) } public var path: Path { return Path(string: url.path) }
public init() throws { public init() throws {
#if os(macOS)
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true) 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 { deinit {