Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Don't say zsh or ssh didn't answer when the reading was stopped

Țugui Dragoș3a029a047886
diff --git a/Peel/Model/SSHLibrary.swift b/Peel/Model/SSHLibrary.swift
index d297aaee..4b7921ee 100644
--- a/Peel/Model/SSHLibrary.swift
+++ b/Peel/Model/SSHLibrary.swift
@@ -33,6 +33,8 @@ final class SSHLibrary {
func refresh() async {
let accepted = if let accepted = state?.accepted { accepted } else { await SSHFile.accepted() }
+ // A reading stopped because the page went away got no answer from ssh, which isn't ssh not answering.
+ guard !Task.isCancelled else { return }
state = State(
settings: SSHFile.read(file),
isIncluded: SSHFile.isIncluded(file, from: config, home: home),
diff --git a/Peel/Model/ShellLibrary.swift b/Peel/Model/ShellLibrary.swift
index 48a6d918..a37bdbe6 100644
--- a/Peel/Model/ShellLibrary.swift
+++ b/Peel/Model/ShellLibrary.swift
@@ -55,6 +55,8 @@ final class ShellLibrary {
}
// Read after zsh answered, which takes as long as the person's startup files: a switch can change it meanwhile.
let choices = ShellFile.read(file)
+ // A reading stopped because the page went away got no answer from zsh, which isn't zsh not answering.
+ guard !Task.isCancelled else { return }
state = State(
shell: shell,
startupFile: startupFile,
diff --git a/PeelTests/TerminalLibrariesTests.swift b/PeelTests/TerminalLibrariesTests.swift
index e8b4c213..70b30ee3 100644
--- a/PeelTests/TerminalLibrariesTests.swift
+++ b/PeelTests/TerminalLibrariesTests.swift
@@ -119,6 +119,26 @@ struct TerminalLibrariesTests {
#expect(ShellFile.read(library.file)?.settings == [.autoCD, .comments])
}
+ @Test func aReadingCutShortIsNoAnswerFromZshOrSSH() async throws {
+ let home = try madeUpHome()
+ defer { try? FileManager.default.removeItem(at: home) }
+ let folder = home.appending(path: "Library/Application Support/Peel", directoryHint: .isDirectory)
+ let terminal = FakeTerminalSettings()
+ terminal.shellSetting = "/bin/zsh"
+ let shell = ShellLibrary(folder: folder, home: home, terminal: terminal)
+ let ssh = SSHLibrary(folder: folder, home: home)
+
+ let reading = Task {
+ withUnsafeCurrentTask { $0?.cancel() }
+ await shell.refresh()
+ await ssh.refresh()
+ }
+ await reading.value
+
+ #expect(shell.state == nil)
+ #expect(ssh.state == nil)
+ }
+
@Test func theShellTabLooksForNoZshrcWhenTerminalOpensBash() async throws {
let home = try madeUpHome()
defer { try? FileManager.default.removeItem(at: home) }