Compare commits

...

3 Commits
0.2.1 ... 0.2.2

Author SHA1 Message Date
Max Howell
f99e7b5ae7 Test iOS, tvOS & watchOS 2019-01-18 13:37:28 -05:00
Max Howell
9553968d66 Add Travis badge 2019-01-18 12:27:05 -05:00
Max Howell
3541c6ec8d Tidy 2019-01-18 09:25:24 -05:00
3 changed files with 66 additions and 15 deletions

View File

@@ -1,14 +1,38 @@
# only run for: merge commits, releases and pull-requests
if: type != push OR branch = master OR branch =~ /^\d+\.\d+(\.\d+)?(-\S*)?$/
os: osx
language: swift
osx_image: xcode10.1
xcode_project: Path.swift.xcodeproj
xcode_scheme: Path.swift-Package
jobs:
include:
- os: osx
language: swift
osx_image: xcode10.1
script: swift test
- script: swift test
name: macOS
- &xcodebuild
before_install: swift package generate-xcodeproj
xcode_destination: platform=iOS Simulator,OS=latest,name=iPhone XS
name: iOS
- <<: *xcodebuild
xcode_destination: platform=tvOS Simulator,OS=latest,name=Apple TV
name: tvOS
- <<: *xcodebuild
name: watchOS
script: |
set -o pipefail
xcodebuild \
-project Path.swift.xcodeproj \
-scheme Path.swift-Package \
-destination 'platform=watchOS Simulator,OS=latest,name=Apple Watch Series 4 - 40mm' \
build | xcpretty
- env: SWIFT_VERSION=4.2.1
os: linux
name: Linux
language: generic
dist: trusty
sudo: false

View File

@@ -1,4 +1,4 @@
# Path.swift
# Path.swift ![badge-platforms] ![badge-languages] [![Build Status](https://travis-ci.com/mxcl/Path.swift.svg)](https://travis-ci.com/mxcl/Path.swift)
A file-system pathing library focused on developer experience and robust
endresults.
@@ -114,16 +114,16 @@ We provide `ls()`, called because it behaves like the Terminal `ls` function,
the name thus implies its behavior, ie. that it is not recursive.
```swift
for path in Path.home.ls() {
print(path.path)
print(path.kind) // .directory or .file
for entry in Path.home.ls() {
print(entry.path)
print(entry.kind) // .directory or .file
}
for path in Path.home.ls() where path.kind == .file {
for entry in Path.home.ls() where entry.kind == .file {
//
}
for path in Path.home.ls() where path.mtime > yesterday {
for entry in Path.home.ls() where entry.path.mtime > yesterday {
//
}
@@ -145,3 +145,7 @@ package.append(.package(url: "https://github.com/mxcl/Path.swift", from: "0.0.0"
### Get push notifications for new releases
https://codebasesaga.com/canopy/
[badge-platforms]: https://img.shields.io/badge/platforms-macOS%20%7C%20Linux%20%7C%20iOS%20%7C%20tvOS%20%7C%20watchOS-lightgrey.svg
[badge-languages]: https://img.shields.io/badge/swift-4.2-orange.svg

View File

@@ -4,17 +4,40 @@ public class TemporaryDirectory {
public let url: URL
public var path: Path { return Path(string: url.path) }
public init() throws {
#if !os(Linux)
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true)
#else
/**
Creates a new temporary directory.
The directory is recursively deleted when this object deallocates.
If you need a temporary directory on a specific volume use the `appropriateFor`
parameter.
- Important: If you are moving a file, ensure to use the `appropriateFor`
parameter, since it is volume aware and moving the file across volumes will take
exponentially longer!
- Important: The `appropriateFor` parameter does not work on Linux.
- Parameter appropriateFor: The temporary directory will be located on this
volume.
*/
public init(appropriateFor: URL? = nil) throws {
#if !os(Linux)
let appropriate: URL
if let appropriateFor = appropriateFor {
appropriate = appropriateFor
} else if #available(OSX 10.12, iOS 10, tvOS 10, watchOS 3, *) {
appropriate = FileManager.default.temporaryDirectory
} else {
appropriate = URL(fileURLWithPath: NSTemporaryDirectory())
}
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: appropriate, 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
#endif
}
deinit {