Skip to content

Commit d3418fa

Browse files
committed
Encapsulated actions that require superuser permissions
This is needed for the next commits and I think it makes the code more organised (it’s clear why a `passwordInput` is being requested, because all actions use it).
1 parent 42d8544 commit d3418fa

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

Sources/XcodesKit/XcodeInstaller.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -529,14 +529,6 @@ public final class XcodeInstaller {
529529
}
530530

531531
public func installArchivedXcode(_ xcode: Xcode, at archiveURL: URL, to destination: Path, experimentalUnxip: Bool = false) -> Promise<InstalledXcode> {
532-
let passwordInput = {
533-
Promise<String> { seal in
534-
Current.logging.log("xcodes requires superuser privileges in order to finish installation.")
535-
guard let password = Current.shell.readSecureLine(prompt: "macOS User Password: ") else { seal.reject(Error.missingSudoerPassword); return }
536-
seal.fulfill(password + "\n")
537-
}
538-
}
539-
540532
return firstly { () -> Promise<InstalledXcode> in
541533
let destinationURL = destination.join("Xcode-\(xcode.version.descriptionWithoutBuildMetadata).app").url
542534
switch archiveURL.pathExtension {
@@ -565,6 +557,19 @@ public final class XcodeInstaller {
565557
.map { xcode }
566558
}
567559
.then { xcode -> Promise<InstalledXcode> in
560+
return self.postInstallXcode(xcode)
561+
}
562+
}
563+
564+
public func postInstallXcode(_ xcode: InstalledXcode) -> Promise<InstalledXcode> {
565+
let passwordInput = {
566+
Promise<String> { seal in
567+
Current.logging.log("xcodes requires superuser privileges in order to finish installation.")
568+
guard let password = Current.shell.readSecureLine(prompt: "macOS User Password: ") else { seal.reject(Error.missingSudoerPassword); return }
569+
seal.fulfill(password + "\n")
570+
}
571+
}
572+
return firstly { () -> Promise<InstalledXcode> in
568573
Current.logging.log(InstallationStep.finishing.description)
569574

570575
return self.enableDeveloperMode(passwordInput: passwordInput).map { xcode }

0 commit comments

Comments
 (0)