Catch and reword xip "not enough free space" error

This commit is contained in:
Brandon Evans 2021-01-23 11:35:24 -07:00
parent d834f3ed74
commit 91293557ec
No known key found for this signature in database
GPG key ID: D58A4B8DB64F8E93
2 changed files with 49 additions and 2 deletions

View file

@ -206,10 +206,15 @@ extension AppState {
return Current.shell.unxip(source)
.catch { error -> AnyPublisher<ProcessOutput, Swift.Error> in
if let executionError = error as? ProcessExecutionError,
executionError.standardError.contains("damaged and cant be expanded") {
if let executionError = error as? ProcessExecutionError {
if executionError.standardError.contains("damaged and cant be expanded") {
return Fail(error: InstallationError.damagedXIP(url: source))
.eraseToAnyPublisher()
} else if executionError.standardError.contains("cant be expanded because the selected volume doesnt have enough free space.") {
return Fail(error: InstallationError.notEnoughFreeSpaceToExpandArchive(archivePath: Path(url: source)!,
version: availableXcode.version))
.eraseToAnyPublisher()
}
}
return Fail(error: error)
.eraseToAnyPublisher()
@ -365,6 +370,7 @@ extension AppState {
public enum InstallationError: LocalizedError, Equatable {
case damagedXIP(url: URL)
case notEnoughFreeSpaceToExpandArchive(archivePath: Path, version: Version)
case failedToMoveXcodeToApplications
case failedSecurityAssessment(xcode: InstalledXcode, output: String)
case codesignVerifyFailed(output: String)
@ -383,6 +389,12 @@ public enum InstallationError: LocalizedError, Equatable {
switch self {
case .damagedXIP(let url):
return "The archive \"\(url.lastPathComponent)\" is damaged and can't be expanded."
case let .notEnoughFreeSpaceToExpandArchive(archivePath, version):
return """
The archive \(archivePath.basename()) cant be expanded because the current volume doesnt have enough free space.
Make more space available to expand the archive and then install Xcode \(version.appleDescription) again to start installation from where it left off.
"""
case .failedToMoveXcodeToApplications:
return "Failed to move Xcode to the /Applications directory."
case .failedSecurityAssessment(let xcode, let output):

View file

@ -280,4 +280,39 @@ class AppStateTests: XCTestCase {
)
}
func test_Install_NotEnoughFreeSpace() throws {
Current.shell.unxip = { _ in
Fail(error: ProcessExecutionError(
process: Process(),
standardOutput: "xip: signing certificate was \"Development Update\" (validation not attempted)",
standardError: "xip: error: The archive “Xcode-12.4.0-Release.Candidate+12D4e.xip” cant be expanded because the selected volume doesnt have enough free space."
))
.eraseToAnyPublisher()
}
let archiveURL = URL(fileURLWithPath: "/Users/user/Library/Application Support/Xcode-0.0.0.xip")
let recorder = subject.unarchiveAndMoveXIP(
availableXcode: AvailableXcode(
version: Version("0.0.0")!,
url: URL(string: "https://developer.apple.com")!,
filename: "Xcode-0.0.0.xip",
releaseDate: nil
),
at: archiveURL,
to: URL(string: "/Applications/Xcode-0.0.0.app")!
).record()
let completion = try wait(for: recorder.completion, timeout: 1, description: "Completion")
if case let .failure(error as InstallationError) = completion {
XCTAssertEqual(
error,
InstallationError.notEnoughFreeSpaceToExpandArchive(archivePath: Path(url: archiveURL)!,
version: Version("0.0.0")!)
)
}
else {
XCTFail()
}
}
}