From 46f7e38b5f7471cd4f42eb31ae14edaea0b0a69b Mon Sep 17 00:00:00 2001 From: John Bute Date: Fri, 7 Feb 2025 12:24:27 -0500 Subject: [PATCH 1/5] Consistency in y/n prompts #141 fix, where certain prompts would fail if the user gave 'Y' instead of 'y' to continue, now all prompting is consistent --- Sources/Swiftly/Init.swift | 6 ++---- Sources/Swiftly/Install.swift | 4 +--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Sources/Swiftly/Init.swift b/Sources/Swiftly/Init.swift index 58053657..1b948720 100644 --- a/Sources/Swiftly/Init.swift +++ b/Sources/Swiftly/Init.swift @@ -77,7 +77,7 @@ internal struct Init: SwiftlyCommand { \(installMsg) """) - if SwiftlyCore.readLine(prompt: "Proceed with the installation? [Y/n] ") == "n" { + guard promptForConfirmation(defaultBehavior: true) else { throw SwiftlyError(message: "Swiftly installation has been cancelled") } } @@ -93,9 +93,7 @@ internal struct Init: SwiftlyCommand { SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)") } - let proceed = SwiftlyCore.readLine(prompt: "Proceed? [y/N]") ?? "n" - - guard proceed == "y" else { + guard promptForConfirmation(defaultBehavior: false) else { throw SwiftlyError(message: "Swiftly installation has been cancelled") } } diff --git a/Sources/Swiftly/Install.swift b/Sources/Swiftly/Install.swift index 6f372907..72c24ddf 100644 --- a/Sources/Swiftly/Install.swift +++ b/Sources/Swiftly/Install.swift @@ -266,9 +266,7 @@ struct Install: SwiftlyCommand { SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)") } - let proceed = SwiftlyCore.readLine(prompt: "Proceed? [y/N]") ?? "n" - - guard proceed == "y" else { + guard promptForConfirmation(defaultBehavior: false) else { throw SwiftlyError(message: "Toolchain installation has been cancelled") } } From 9826fc2cc4c5a39e9347b1f17284d5201b5acc48 Mon Sep 17 00:00:00 2001 From: John Bute Date: Tue, 11 Feb 2025 11:21:55 -0500 Subject: [PATCH 2/5] Fixed bug where child process did not set parent process back to foreground --- Sources/SwiftlyCore/Platform.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 780afe18..2b0613fb 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -211,6 +211,10 @@ extension Platform { } process.waitUntilExit() + if pgid != -1 { + tcsetpgrp(STDOUT_FILENO, pgid) + } + guard process.terminationStatus == 0 else { throw RunProgramError(exitCode: process.terminationStatus, program: args.first!) } @@ -254,6 +258,10 @@ extension Platform { process.waitUntilExit() + if pgid != -1 { + tcsetpgrp(STDOUT_FILENO, pgid) + } + guard process.terminationStatus == 0 else { throw RunProgramError(exitCode: process.terminationStatus, program: args.first!) } From 91dc698fd26d3a9eb532cc0252c34508f06077ab Mon Sep 17 00:00:00 2001 From: John Bute Date: Wed, 12 Feb 2025 11:40:08 -0500 Subject: [PATCH 3/5] fixed formatting and added defer --- Sources/Swiftly/Init.swift | 2 +- Sources/SwiftlyCore/Platform.swift | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Swiftly/Init.swift b/Sources/Swiftly/Init.swift index 1b948720..5a70a1a3 100644 --- a/Sources/Swiftly/Init.swift +++ b/Sources/Swiftly/Init.swift @@ -93,7 +93,7 @@ internal struct Init: SwiftlyCommand { SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)") } - guard promptForConfirmation(defaultBehavior: false) else { + guard SwiftlyCore.promptForConfirmation(defaultBehavior: false) else { throw SwiftlyError(message: "Swiftly installation has been cancelled") } } diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index 2b0613fb..f6893311 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -211,9 +211,9 @@ extension Platform { } process.waitUntilExit() - if pgid != -1 { + defer { if pgid != -1 { tcsetpgrp(STDOUT_FILENO, pgid) - } + }} guard process.terminationStatus == 0 else { throw RunProgramError(exitCode: process.terminationStatus, program: args.first!) @@ -258,9 +258,9 @@ extension Platform { process.waitUntilExit() - if pgid != -1 { + defer { if pgid != -1 { tcsetpgrp(STDOUT_FILENO, pgid) - } + }} guard process.terminationStatus == 0 else { throw RunProgramError(exitCode: process.terminationStatus, program: args.first!) From 5c2c0d460fb67d99c0fe536d653f5f61c7bdd2a5 Mon Sep 17 00:00:00 2001 From: John Bute Date: Wed, 12 Feb 2025 11:44:28 -0500 Subject: [PATCH 4/5] fixed formatting issue --- Sources/Swiftly/Install.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/Swiftly/Install.swift b/Sources/Swiftly/Install.swift index 4882a342..1d3b1553 100644 --- a/Sources/Swiftly/Install.swift +++ b/Sources/Swiftly/Install.swift @@ -266,7 +266,6 @@ struct Install: SwiftlyCommand { SwiftlyCore.print(" \(swiftlyBinDir.appendingPathComponent(executable).path)") } - guard SwiftlyCore.promptForConfirmation(defaultBehavior: false) else { throw SwiftlyError(message: "Toolchain installation has been cancelled") } From 4b5165a380166a99b1c652fd3fce2365f878d23d Mon Sep 17 00:00:00 2001 From: John Bute Date: Thu, 13 Feb 2025 12:04:29 -0500 Subject: [PATCH 5/5] improved locality of defer --- Sources/SwiftlyCore/Platform.swift | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/SwiftlyCore/Platform.swift b/Sources/SwiftlyCore/Platform.swift index f6893311..44af8c39 100644 --- a/Sources/SwiftlyCore/Platform.swift +++ b/Sources/SwiftlyCore/Platform.swift @@ -209,12 +209,13 @@ extension Platform { if pgid != -1 { tcsetpgrp(STDOUT_FILENO, process.processIdentifier) } - process.waitUntilExit() defer { if pgid != -1 { tcsetpgrp(STDOUT_FILENO, pgid) }} + process.waitUntilExit() + guard process.terminationStatus == 0 else { throw RunProgramError(exitCode: process.terminationStatus, program: args.first!) } @@ -254,14 +255,14 @@ extension Platform { if pgid != -1 { tcsetpgrp(STDOUT_FILENO, process.processIdentifier) } - let outData = try outPipe.fileHandleForReading.readToEnd() - - process.waitUntilExit() - defer { if pgid != -1 { tcsetpgrp(STDOUT_FILENO, pgid) }} + let outData = try outPipe.fileHandleForReading.readToEnd() + + process.waitUntilExit() + guard process.terminationStatus == 0 else { throw RunProgramError(exitCode: process.terminationStatus, program: args.first!) }