Skip to content

Commit

Permalink
Remove XIP after unarchiving Xcode
Browse files Browse the repository at this point in the history
This should probably only happen if the XIP is in the app support directory, but since that's the most common use case I'm punting on the conditions for the other cases for now.
  • Loading branch information
interstateone committed Mar 10, 2019
1 parent c049c31 commit 1bc2e8c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Sources/XcodesKit/Environment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,10 @@ struct Files {
func contents(atPath path: String) -> Data? {
return contentsAtPath(path)
}

var removeItem: (URL) throws -> Void = { try FileManager.default.removeItem(at: $0) }

func removeItem(at URL: URL) throws {
try removeItem(URL)
}
}
2 changes: 2 additions & 0 deletions Sources/XcodesKit/XcodeInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public final class XcodeInstaller {
}
}
.then { xcode -> Promise<InstalledXcode> in
try Current.files.removeItem(at: url)

return when(fulfilled: self.verifySecurityAssessment(of: xcode.path.url),
self.verifySigningCertificate(of: xcode.path.url))
.map { xcode }
Expand Down
3 changes: 2 additions & 1 deletion Tests/XcodesKitTests/Environment+Mock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extension Files {
contentsAtPath: { _ in
let url = URL(fileURLWithPath: "Stub.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent())
return try? Data(contentsOf: url)
}
},
removeItem: { _ in }
)
}
10 changes: 10 additions & 0 deletions Tests/XcodesKitTests/XcodesKitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ final class XcodesKitTests: XCTestCase {
.catch { error in XCTAssertEqual(error as! XcodeInstaller.Error, XcodeInstaller.Error.codesignVerifyFailed) }
}

func test_InstallArchivedXcode_RemovesXIPWhenFinished() {
var removedItemAtURL: URL?
Current.files.removeItem = { removedItemAtURL = $0 }

let xcode = Xcode(version: Version("0.0.0")!, url: URL(fileURLWithPath: "/"), filename: "mock")
let xipURL = URL(fileURLWithPath: "/Xcode-0.0.0.xip")
installer.installArchivedXcode(xcode, at: xipURL, passwordInput: { Promise.value("") })
.ensure { XCTAssertEqual(removedItemAtURL, xipURL) }
}

func test_VerifySecurityAssessment_Fails() {
Current.shell.spctlAssess = { _ in return Promise(error: Process.PMKError.execution(process: Process(), standardOutput: nil, standardError: nil)) }

Expand Down

0 comments on commit 1bc2e8c

Please sign in to comment.