Skip to content

Commit b6c3411

Browse files
committed
(+ Install ^ Uninstall) of versioned packages
1 parent 6c6e095 commit b6c3411

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

Cork/Logic/Installation & Removal/Removal/Uninstall Packages.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ extension BrewDataStorage
3737
}
3838
}
3939

40-
AppConstants.shared.logger.info("Will try to remove package \(package.name, privacy: .auto)")
40+
AppConstants.shared.logger.info("Will try to remove package \(package.fullName, privacy: .auto)")
4141
var uninstallCommandOutput: TerminalOutput
4242

4343
if !shouldRemoveAllAssociatedFiles
4444
{
45-
uninstallCommandOutput = await shell(AppConstants.shared.brewExecutablePath, ["uninstall", package.name])
45+
uninstallCommandOutput = await shell(AppConstants.shared.brewExecutablePath, ["uninstall", package.fullName])
4646
}
4747
else
4848
{
49-
uninstallCommandOutput = await shell(AppConstants.shared.brewExecutablePath, ["uninstall", "--zap", package.name])
49+
uninstallCommandOutput = await shell(AppConstants.shared.brewExecutablePath, ["uninstall", "--zap", package.fullName])
5050
}
5151

5252
AppConstants.shared.logger.warning("Uninstall process Standard error: \(uninstallCommandOutput.standardError)")
@@ -116,7 +116,7 @@ extension BrewDataStorage
116116
AppConstants.shared.logger.info("Package uninstallation process output:\nStandard output: \(uninstallCommandOutput.standardOutput, privacy: .public)\nStandard error: \(uninstallCommandOutput.standardError, privacy: .public)")
117117

118118
/// If the user removed a package that was outdated, remove it from the outdated package tracker
119-
if let index = outdatedPackageTracker.displayableOutdatedPackages.firstIndex(where: { $0.package.name == package.name })
119+
if let index = outdatedPackageTracker.displayableOutdatedPackages.firstIndex(where: { $0.package.name == package.fullName })
120120
{
121121
outdatedPackageTracker.outdatedPackages.remove(at: index)
122122
}

Cork/Models/Package Installation/Installation Progress Tracker.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
// Created by David Bureš on 22.02.2023.
66
//
77

8-
import Foundation
98
import CorkShared
9+
import Foundation
1010

1111
class InstallationProgressTracker: ObservableObject
1212
{
1313
@Published var installationStage: PackageInstallationStage = .downloadingCask
1414
@Published var installationProgress: Double = 0
15-
15+
1616
@Published var realTimeTerminalOutput: [RealTimeTerminalLine] = .init()
17-
17+
1818
@Published var numberOfPackageDependencies: Int = 0
1919
@Published var numberInLineOfPackageCurrentlyBeingFetched: Int = 0
2020
@Published var numberInLineOfPackageCurrentlyBeingInstalled: Int = 0
21-
21+
2222
private var installationProcess: Process?
2323

2424
private var showRealTimeTerminalOutputs: Bool
2525
{
2626
UserDefaults.standard.bool(forKey: "showRealTimeTerminalOutputOfOperations")
2727
}
28-
28+
2929
deinit
3030
{
3131
cancel()
3232
}
33-
33+
3434
@discardableResult
3535
func cancel() -> Bool
3636
{
37-
guard let installationProcess else {return false}
37+
guard let installationProcess else { return false }
3838
installationProcess.terminate()
3939
self.installationProcess = nil
4040
return true
@@ -87,7 +87,7 @@ class InstallationProgressTracker: ObservableObject
8787

8888
AppConstants.shared.logger.info("Package \(packageToInstall.name, privacy: .public) is Formula")
8989

90-
let (stream, process): (AsyncStream<StreamedTerminalOutput>, Process) = shell(AppConstants.shared.brewExecutablePath, ["install", packageToInstall.name])
90+
let (stream, process): (AsyncStream<StreamedTerminalOutput>, Process) = shell(AppConstants.shared.brewExecutablePath, ["install", packageToInstall.fullName])
9191
installationProcess = process
9292
for await output in stream
9393
{
@@ -107,7 +107,7 @@ class InstallationProgressTracker: ObservableObject
107107
if outputLine.contains("Fetching dependencies")
108108
{
109109
// First, we have to get a list of all the dependencies
110-
var matchedDependencies: String = try outputLine.regexMatch("(?<=\(packageToInstall.name): ).*?(.*)")
110+
var matchedDependencies: String = try outputLine.regexMatch("(?<=\(packageToInstall.fullName): ).*?(.*)")
111111
matchedDependencies = matchedDependencies.replacingOccurrences(of: " and", with: ",") // The last dependency is different, because it's preceded by "and" instead of "," so let's replace that "and" with "," so we can split it nicely
112112

113113
AppConstants.shared.logger.debug("Matched Dependencies: \(matchedDependencies, privacy: .auto)")
@@ -170,7 +170,7 @@ class InstallationProgressTracker: ObservableObject
170170

171171
installOutput.append(outputLine)
172172

173-
AppConstants.shared.logger.debug("Current installation stage: \(self.installationStage.description, privacy: .public)")
173+
AppConstants.shared.logger.debug("Current installation stage: \(self.installationStage.description, privacy: .public)")
174174

175175
case .standardError(let errorLine):
176176
AppConstants.shared.logger.error("Errored out: \(errorLine, privacy: .public)")
@@ -202,7 +202,7 @@ class InstallationProgressTracker: ObservableObject
202202
AppConstants.shared.logger.info("Package is Cask")
203203
AppConstants.shared.logger.debug("Installing package \(packageToInstall.name, privacy: .public)")
204204

205-
let (stream, process): (AsyncStream<StreamedTerminalOutput>, Process) = shell(AppConstants.shared.brewExecutablePath, ["install", "--no-quarantine", packageToInstall.name])
205+
let (stream, process): (AsyncStream<StreamedTerminalOutput>, Process) = shell(AppConstants.shared.brewExecutablePath, ["install", "--no-quarantine", packageToInstall.fullName])
206206
installationProcess = process
207207
for await output in stream
208208
{
@@ -213,7 +213,7 @@ class InstallationProgressTracker: ObservableObject
213213

214214
if showRealTimeTerminalOutputs
215215
{
216-
realTimeTerminalOutput.append(RealTimeTerminalLine(line: outputLine))
216+
realTimeTerminalOutput.append(RealTimeTerminalLine(line: outputLine))
217217
}
218218

219219
if outputLine.contains("Downloading")

Cork/Models/Packages/Brew Package.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@ import CorkShared
1414
struct BrewPackage: Identifiable, Equatable, Hashable, Codable
1515
{
1616
var id: UUID = .init()
17+
/// Display name for the package. Excludes Homebrew version
1718
let name: String
19+
20+
/// Internal Homebrew name for the package. Includes Homebrew version
21+
var fullName: String {
22+
if let sanitizedHomewbrewVersion = self.homebrewVersion
23+
{
24+
return "\(self.name)@\(sanitizedHomewbrewVersion)"
25+
}
26+
else
27+
{
28+
return self.name
29+
}
30+
}
1831

1932
lazy var sanitizedName: String? = {
2033
var packageNameWithoutTap: String

Cork/Views/Installation/Sub-Views/Initial.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ struct InstallationInitialView: View
118118
{
119119
Button
120120
{
121-
guard let packageToInstall: BrewPackage = foundPackageSelection?.package else
121+
guard let packageToInstall: BrewPackage = foundPackageSelection?.constructPackageOfRelevantVersion() else
122122
{
123123
AppConstants.shared.logger.error("Could not retrieve top package to install")
124124

Cork/Views/Installation/Sub-Views/Presenting Search Results.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ struct PresentingSearchResultsView: View
161161
// This has to be an AsyncButton so it shakes
162162
AsyncButton
163163
{
164-
guard let packageToInstall = foundPackageSelection?.package
164+
guard let packageToInstall = foundPackageSelection?.constructPackageOfRelevantVersion()
165165
else
166166
{
167167
throw PackageInstallationInitializationError.couldNotStartInstallProcessWithPackage(package: nil)

0 commit comments

Comments
 (0)