Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cac06d89fb | ||
|
|
4af0ee3983 |
16
.travis.yml
Normal file
16
.travis.yml
Normal 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
|
||||||
@@ -14,6 +14,10 @@ public extension Bundle {
|
|||||||
public var resources: Path? {
|
public var resources: Path? {
|
||||||
return resourcePath.flatMap(Path.init)
|
return resourcePath.flatMap(Path.init)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var path: Path {
|
||||||
|
return Path(string: bundlePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public extension String {
|
public extension String {
|
||||||
@@ -43,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 = []
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,15 @@ public extension Path {
|
|||||||
return rv
|
return rv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@discardableResult
|
||||||
|
public func move(to: Path, overwrite: Bool = false) throws -> Path {
|
||||||
|
if overwrite, to.exists {
|
||||||
|
try FileManager.default.removeItem(at: to.url)
|
||||||
|
}
|
||||||
|
try FileManager.default.moveItem(at: url, to: to.url)
|
||||||
|
return to
|
||||||
|
}
|
||||||
|
|
||||||
@discardableResult
|
@discardableResult
|
||||||
public func move(into: Path) throws -> Path {
|
public func move(into: Path) throws -> Path {
|
||||||
if !into.exists {
|
if !into.exists {
|
||||||
@@ -48,8 +57,9 @@ public extension Path {
|
|||||||
} else if !into.isDirectory {
|
} else if !into.isDirectory {
|
||||||
throw CocoaError.error(.fileWriteFileExists)
|
throw CocoaError.error(.fileWriteFileExists)
|
||||||
}
|
}
|
||||||
try FileManager.default.moveItem(at: url, to: into.join(basename()).url)
|
let rv = into/basename()
|
||||||
return self
|
try FileManager.default.moveItem(at: url, to: rv.url)
|
||||||
|
return rv
|
||||||
}
|
}
|
||||||
|
|
||||||
@inlinable
|
@inlinable
|
||||||
|
|||||||
@@ -15,6 +15,10 @@ public extension Path {
|
|||||||
return FileManager.default.fileExists(atPath: string, isDirectory: &isDir) && !isDir.boolValue
|
return FileManager.default.fileExists(atPath: string, isDirectory: &isDir) && !isDir.boolValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isExecutable: Bool {
|
||||||
|
return FileManager.default.isExecutableFile(atPath: string)
|
||||||
|
}
|
||||||
|
|
||||||
var exists: Bool {
|
var exists: Bool {
|
||||||
return FileManager.default.fileExists(atPath: string)
|
return FileManager.default.fileExists(atPath: string)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user