Compare commits

..

10 Commits
0.4.4 ... 0.5.0

Author SHA1 Message Date
Max Howell
db135e32c8 Tag 0.5.0 2019-01-25 11:08:57 -05:00
Max Howell
bfcc48db20 Merge pull request #10 from mxcl/fixes
Swift 5 / Xcode 10.2 / Fixes
2019-01-25 11:04:35 -05:00
Max Howell
b0bf0d0074 This is not yet fixed in Linux Swift 5.0 2019-01-25 10:55:02 -05:00
Max Howell
5f364fe21b Test against Swift 5 snapshot 2019-01-25 10:40:10 -05:00
Max Howell
fdff3bcc05 Swift 5 --warnings 2019-01-24 15:02:06 -05:00
Max Howell
2388c384a1 Swift 5 Manifest (untested until Travis catches up) 2019-01-24 15:01:53 -05:00
Max Howell
80960f5876 Don’t overwrite a file with a directory 2019-01-24 14:44:01 -05:00
Max Howell
9eca479f7b Fix mtime return so it is as per doc contract 2019-01-24 14:43:45 -05:00
Max Howell
ca9f1e0a74 Parallelize tests 2019-01-23 11:25:51 -05:00
Max Howell
de4fb3ae47 Remove replaceContents, user can use String.write 2019-01-22 17:57:28 -05:00
6 changed files with 66 additions and 63 deletions

View File

@@ -15,18 +15,18 @@ xcode_scheme: Path.swift-Package
jobs:
include:
- script: swift test
name: macOS
- script: swift test --parallel
name: macOS / Swift 4.2.1
- &xcodebuild
before_install: swift package generate-xcodeproj
xcode_destination: platform=iOS Simulator,OS=latest,name=iPhone XS
name: iOS
name: iOS / Swift 4.2.1
- <<: *xcodebuild
xcode_destination: platform=tvOS Simulator,OS=latest,name=Apple TV
name: tvOS
name: tvOS / Swift 4.2.1
- <<: *xcodebuild
name: watchOS
name: watchOS / Swift 4.2.1
script: |
set -o pipefail
xcodebuild \
@@ -35,17 +35,22 @@ jobs:
-destination 'platform=watchOS Simulator,OS=latest,name=Apple Watch Series 4 - 40mm' \
build | xcpretty
- env: SWIFT_VERSION=4.2.1
- &linux
env: SWIFT_VERSION=4.2.1
os: linux
name: Linux
name: Linux / Swift 4.2.1
language: generic
dist: trusty
sudo: false
install: eval "$(curl -sL https://swiftenv.fuller.li/install.sh)"
script: swift test
script: swift test --parallel
- <<: *linux
env: SWIFT_VERSION='5.0-DEVELOPMENT-SNAPSHOT-2019-01-22-a'
name: Linux / Swift 5.0.0-dev (2019-01-22)
- stage: pretest
name: Check if Linux tests are up-to-date
name: Check Linux tests are syncd
install: swift test --generate-linuxmain
script: git diff --exit-code
@@ -66,9 +71,9 @@ jobs:
github_url: https://github.com/mxcl/Path.swift
EOF
sed -i '' "s/TRAVIS_TAG/$TRAVIS_TAG/" .jazzy.yaml
# ^^ this weirdness because Travis multiline YAML is broken and inserts two
# spaces in front of the output which means we need a prefixed delimiter which
# also weirdly stops bash from doing variable substitution
# ^^ this weirdness because Travis multiline YAML is broken and inserts
# two spaces in front of the output which means we need a prefixed
# delimiter which also weirdly stops bash from doing variable substitution
install: gem install jazzy
before_script: swift package generate-xcodeproj
script: jazzy

20
Package@swift-5.0.swift Normal file
View File

@@ -0,0 +1,20 @@
// swift-tools-version:5.0
import PackageDescription
let pkg = Package(
name: "Path.swift",
products: [
.library(name: "Path", targets: ["Path"]),
],
targets: [
.target(name: "Path", path: "Sources"),
.testTarget(name: "PathTests", dependencies: ["Path"]),
]
)
pkg.platforms = [
.macOS(.v10_10), .iOS(.v8), .tvOS(.v10), .watchOS(.v3)
]
pkg.swiftLanguageVersions = [
.v4_2, .v5
]

View File

@@ -191,17 +191,23 @@ Path("~foo") // => nil
SwiftPM:
```swift
package.append(.package(url: "https://github.com/mxcl/Path.swift", from: "0.4.1"))
package.append(.package(url: "https://github.com/mxcl/Path.swift", from: "0.5.0"))
```
CocoaPods:
```ruby
pod 'Path.swift' ~> '0.4.1'
pod 'Path.swift' ~> '0.5.0'
```
Please note! We are pre 1.0, thus we can change the API as we like! We will tag
1.0 as soon as possible.
Carthage:
> Waiting on: [@Carthage#1945](https://github.com/Carthage/Carthage/pull/1945).
## Please note
We are pre 1.0, thus we can change the API as we like, and we will (to the
pursuit of getting it *right*)! We will tag 1.0 as soon as possible.
### Get push notifications for new releases

View File

@@ -10,17 +10,17 @@ public extension Bundle {
}
/// Returns the path for the shared-frameworks directory in this bundle.
public var sharedFrameworks: Path? {
var sharedFrameworks: Path? {
return sharedFrameworksPath.flatMap(Path.init)
}
/// Returns the path for the resources directory in this bundle.
public var resources: Path? {
var resources: Path? {
return resourcePath.flatMap(Path.init)
}
/// Returns the path for this bundle.
public var path: Path {
var path: Path {
return Path(string: bundlePath)
}
}

View File

@@ -4,7 +4,7 @@ public extension Path {
/// - Note: If file is already locked, does nothing
/// - Note: If file doesnt exist, throws
@discardableResult
public func lock() throws -> Path {
func lock() throws -> Path {
var attrs = try FileManager.default.attributesOfItem(atPath: string)
let b = attrs[.immutable] as? Bool ?? false
if !b {
@@ -17,7 +17,7 @@ public extension Path {
/// - Note: If file isnt locked, does nothing
/// - Note: If file doesnt exist, does nothing
@discardableResult
public func unlock() throws -> Path {
func unlock() throws -> Path {
var attrs: [FileAttributeKey: Any]
do {
attrs = try FileManager.default.attributesOfItem(atPath: string)
@@ -38,7 +38,7 @@ public extension Path {
Path.home.join("foo").chmod(0o555)
*/
@discardableResult
public func chmod(_ octal: Int) throws -> Path {
func chmod(_ octal: Int) throws -> Path {
try FileManager.default.setAttributes([.posixPermissions: octal], ofItemAtPath: string)
return self
}
@@ -48,10 +48,10 @@ public extension Path {
- Note: Returns the creation time if there is no modification time.
- Note: Returns UNIX-time-zero if neither are available, though this *should* be impossible.
*/
public var mtime: Date {
var mtime: Date {
do {
let attrs = try FileManager.default.attributesOfItem(atPath: string)
return attrs[.modificationDate] as? Date ?? attrs[.creationDate] as? Date ?? Date()
return attrs[.modificationDate] as? Date ?? attrs[.creationDate] as? Date ?? Date(timeIntervalSince1970: 0)
} catch {
//TODO log error
return Date(timeIntervalSince1970: 0)

View File

@@ -5,13 +5,14 @@ public extension Path {
Copies a file.
- Note: `throws` if `to` is a directory.
- Parameter to: Destination filename.
- Parameter overwrite: If true overwrites any file that already exists at `to`.
- Parameter overwrite: If `true` and both `self` and `to` are files, overwrites `to`.
- Note: If either `self` or `to are directories, `overwrite` is ignored.
- Returns: `to` to allow chaining
- SeeAlso: `copy(into:overwrite:)`
*/
@discardableResult
public func copy(to: Path, overwrite: Bool = false) throws -> Path {
if overwrite, to.exists {
func copy(to: Path, overwrite: Bool = false) throws -> Path {
if overwrite, to.isFile, isFile {
try FileManager.default.removeItem(at: to.url)
}
try FileManager.default.copyItem(atPath: string, toPath: to.string)
@@ -33,7 +34,7 @@ public extension Path {
- SeeAlso: `copy(into:overwrite:)`
*/
@discardableResult
public func copy(into: Path, overwrite: Bool = false) throws -> Path {
func copy(into: Path, overwrite: Bool = false) throws -> Path {
if !into.exists {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
}
@@ -42,7 +43,7 @@ public extension Path {
try rv.delete()
}
#if os(Linux)
#if swift(>=5)
#if swift(>=5.1)
// check if fixed
#else
if !overwrite, rv.isFile {
@@ -63,7 +64,7 @@ public extension Path {
- SeeAlso: move(into:overwrite:)
*/
@discardableResult
public func move(to: Path, overwrite: Bool = false) throws -> Path {
func move(to: Path, overwrite: Bool = false) throws -> Path {
if overwrite, to.exists {
try FileManager.default.removeItem(at: to.url)
}
@@ -83,7 +84,7 @@ public extension Path {
- SeeAlso: move(into:overwrite:)
*/
@discardableResult
public func move(into: Path) throws -> Path {
func move(into: Path) throws -> Path {
if !into.exists {
try into.mkpath()
} else if !into.isDirectory {
@@ -96,7 +97,7 @@ public extension Path {
/// Deletes the path, recursively if a directory.
@inlinable
public func delete() throws {
func delete() throws {
try FileManager.default.removeItem(at: url)
}
@@ -136,7 +137,7 @@ public extension Path {
- Returns: `self` to allow chaining.
*/
@discardableResult
public func mkdir() throws -> Path {
func mkdir() throws -> Path {
try _foo {
try FileManager.default.createDirectory(at: self.url, withIntermediateDirectories: false, attributes: nil)
}
@@ -149,39 +150,10 @@ public extension Path {
- Returns: `self` to allow chaining.
*/
@discardableResult
public func mkpath() throws -> Path {
func mkpath() throws -> Path {
try _foo {
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true, attributes: nil)
}
return self
}
/**
Replaces the contents of the file at this path with the provided string.
- Note: If file doesnt exist, creates file
- Note: If file is not writable, makes writable first, resetting permissions after the write
- Parameter contents: The string that will become the contents of this file.
- Parameter atomically: If `true` the operation will be performed atomically.
- Parameter encoding: The string encoding to use.
- Returns: `self` to allow chaining.
*/
@discardableResult
public func replaceContents(with contents: String, atomically: Bool = false, encoding: String.Encoding = .utf8) throws -> Path {
let resetPerms: Int?
if exists, !isWritable {
resetPerms = try FileManager.default.attributesOfItem(atPath: string)[.posixPermissions] as? Int
let perms = resetPerms ?? 0o777
try chmod(perms | 0o200)
} else {
resetPerms = nil
}
defer {
_ = try? resetPerms.map(self.chmod)
}
try contents.write(to: self)
return self
}
}