Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f99e7b5ae7 | ||
|
|
9553968d66 | ||
|
|
3541c6ec8d |
32
.travis.yml
32
.travis.yml
@@ -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
|
||||
|
||||
16
README.md
16
README.md
@@ -1,4 +1,4 @@
|
||||
# Path.swift
|
||||
# Path.swift ![badge-platforms] ![badge-languages] [](https://travis-ci.com/mxcl/Path.swift)
|
||||
|
||||
A file-system pathing library focused on developer experience and robust
|
||||
end‐results.
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user