From 66ae86c986aab97feae807068efae06599318ea2 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 31 Jan 2019 08:37:14 -0500 Subject: [PATCH 1/4] Enable codecov.io --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f482da7..fe57b5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,9 +19,10 @@ jobs: name: macOS / Swift 4.2.1 - &xcodebuild - before_install: swift package generate-xcodeproj + before_install: swift package generate-xcodeproj --enable-code-coverage xcode_destination: platform=iOS Simulator,OS=latest,name=iPhone XS name: iOS / Swift 4.2.1 + after_success: bash <(curl -s https://codecov.io/bash) - <<: *xcodebuild xcode_destination: platform=tvOS Simulator,OS=latest,name=Apple TV name: tvOS / Swift 4.2.1 @@ -34,6 +35,7 @@ jobs: -scheme Path.swift-Package \ -destination 'platform=watchOS Simulator,OS=latest,name=Apple Watch Series 4 - 40mm' \ build | xcpretty + after_success: false - &linux env: SWIFT_VERSION=4.2.1 From eb34ac4af886e8526c138f86aceb0464285834fe Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 31 Jan 2019 08:37:32 -0500 Subject: [PATCH 2/4] Add overwrite parameter to move(into:) --- Sources/Path+FileManager.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/Path+FileManager.swift b/Sources/Path+FileManager.swift index 20e39be..5f3a428 100644 --- a/Sources/Path+FileManager.swift +++ b/Sources/Path+FileManager.swift @@ -90,7 +90,7 @@ public extension Path { */ @discardableResult func move(to: Path, overwrite: Bool = false) throws -> Path { - if overwrite, to.exists { + if overwrite, to.isFile { try FileManager.default.removeItem(at: to.url) } try FileManager.default.moveItem(at: url, to: to.url) @@ -112,13 +112,16 @@ public extension Path { - SeeAlso: move(into:overwrite:) */ @discardableResult - func move(into: Path) throws -> Path { + func move(into: Path, overwrite: Bool = false) throws -> Path { if !into.exists { try into.mkdir(.p) } else if !into.isDirectory { throw CocoaError.error(.fileWriteFileExists) } let rv = into/basename() + if overwrite, rv.isFile { + try FileManager.default.removeItem(at: rv.url) + } try FileManager.default.moveItem(at: url, to: rv.url) return rv } From c6e840b9b6c2a0f66eac6636e6c8a83ad7e8e76f Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 31 Jan 2019 08:38:00 -0500 Subject: [PATCH 3/4] Add `rename` --- Sources/Path+FileManager.swift | 7 +++++ Tests/PathTests/PathTests.swift | 40 +++++++++++++++++++++++---- Tests/PathTests/XCTestManifests.swift | 2 ++ 3 files changed, 44 insertions(+), 5 deletions(-) diff --git a/Sources/Path+FileManager.swift b/Sources/Path+FileManager.swift index 5f3a428..2e3484a 100644 --- a/Sources/Path+FileManager.swift +++ b/Sources/Path+FileManager.swift @@ -174,6 +174,13 @@ public extension Path { } return self } + + @discardableResult + func rename(_ newname: String) throws -> Path { + let newpath = parent/newname + try FileManager.default.moveItem(atPath: string, toPath: newpath.string) + return newpath + } } /// Options for `Path.mkdir(_:)` diff --git a/Tests/PathTests/PathTests.swift b/Tests/PathTests/PathTests.swift index 5224bb0..59784a7 100644 --- a/Tests/PathTests/PathTests.swift +++ b/Tests/PathTests/PathTests.swift @@ -165,12 +165,42 @@ class PathTests: XCTestCase { } func testCopyInto() throws { + try Path.mktemp { root1 in + let bar1 = try root1.join("bar").touch() + try Path.mktemp { root2 in + let bar2 = try root2.join("bar").touch() + XCTAssertThrowsError(try bar1.copy(into: root2)) + try bar1.copy(into: root2, overwrite: true) + XCTAssertTrue(bar1.exists) + XCTAssertTrue(bar2.exists) + } + } + } + + func testMoveInto() throws { + try Path.mktemp { root1 in + let bar1 = try root1.join("bar").touch() + try Path.mktemp { root2 in + let bar2 = try root2.join("bar").touch() + XCTAssertThrowsError(try bar1.move(into: root2)) + try bar1.move(into: root2, overwrite: true) + XCTAssertFalse(bar1.exists) + XCTAssertTrue(bar2.exists) + } + } + } + + func testRename() throws { try Path.mktemp { root in - let bar = try root.join("bar").touch() - try Path.mktemp { root in - try root.join("bar").touch() - XCTAssertThrowsError(try bar.copy(into: root)) - try bar.copy(into: root, overwrite: true) + do { + let file = try root.bar.touch() + let foo = try file.rename("foo") + XCTAssertFalse(file.exists) + XCTAssertTrue(foo.isFile) + } + do { + let file = try root.bar.touch() + XCTAssertThrowsError(try file.rename("foo")) } } } diff --git a/Tests/PathTests/XCTestManifests.swift b/Tests/PathTests/XCTestManifests.swift index 06ae5f0..ccfec17 100644 --- a/Tests/PathTests/XCTestManifests.swift +++ b/Tests/PathTests/XCTestManifests.swift @@ -15,8 +15,10 @@ extension PathTests { ("testJoin", testJoin), ("testMkpathIfExists", testMkpathIfExists), ("testMktemp", testMktemp), + ("testMoveInto", testMoveInto), ("testRelativePathCodable", testRelativePathCodable), ("testRelativeTo", testRelativeTo), + ("testRename", testRename), ] } From f1cd06fdff086d2dd633ae77a0148dc790ae5a92 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Thu, 31 Jan 2019 09:58:36 -0500 Subject: [PATCH 4/4] Add CI post success hook yamls --- .github/codecov.yml | 2 ++ .github/ranger.yml | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 .github/codecov.yml create mode 100644 .github/ranger.yml diff --git a/.github/codecov.yml b/.github/codecov.yml new file mode 100644 index 0000000..3922952 --- /dev/null +++ b/.github/codecov.yml @@ -0,0 +1,2 @@ +ignore: + - Tests diff --git a/.github/ranger.yml b/.github/ranger.yml new file mode 100644 index 0000000..380c58e --- /dev/null +++ b/.github/ranger.yml @@ -0,0 +1,3 @@ +merges: + - action: delete_branch + - action: tag