`swift-format lint --strict --recursive Termind TermindTests
TermindMCPBridge` is in the contribution instructions but had never been
run to completion: 4133 violations across 141 files, most of them
indentation and line breaking the pretty-printer would have settled on
its own.
`swift-format format -i` accounts for all but five. The rest are
lint-only rules it will not rewrite for you:
- `SSHKeyMaterial` declared its libssh2 entry point in the C symbol's
own spelling. `@_silgen_name` already carries the linkage name, so the
Swift side is free to be `libssh2PublicKeyFromPrivateMemory`.
- Four `.forEach { ... }` calls become for-in loops, two in
`PortForwardingController` and two in tests.
Formatting only, and checked as such rather than assumed: all 5409
string literals under `Termind` are byte-identical across the change, so
no localization key moved. Comparing whitespace-stripped token streams
leaves 43 files with any real change, and each is one of the rules
above, a dropped semicolon, a `case a, b` split onto separate lines with
its raw values kept explicit, or a file-scope `private` respelled
`fileprivate` — which is the same access level in that position.
Builds, and the suite stays at 975 of 975.
65 lines
1.9 KiB
Swift
65 lines
1.9 KiB
Swift
import Foundation
|
|
|
|
@MainActor
|
|
@Observable
|
|
final class SFTPHistoryModel {
|
|
static let perHostLimit = 1_000
|
|
|
|
private let repository: any SFTPHistoryRepository
|
|
private(set) var revision: UInt64 = 0
|
|
private(set) var storageError: String?
|
|
|
|
init(
|
|
entries: [SFTPHistoryEntry] = [],
|
|
repository: (any SFTPHistoryRepository)? = nil
|
|
) {
|
|
self.repository = repository ?? InMemorySFTPHistoryRepository(entries: entries)
|
|
}
|
|
|
|
func entries(for hostID: Host.ID, matching query: String = "") -> [SFTPHistoryEntry] {
|
|
let values: [SFTPHistoryEntry]
|
|
do {
|
|
values = try repository.entries(for: hostID)
|
|
storageError = nil
|
|
} catch {
|
|
storageError = error.localizedDescription
|
|
return []
|
|
}
|
|
guard !query.isEmpty else { return values }
|
|
return values.filter { $0.path.localizedCaseInsensitiveContains(query) }
|
|
}
|
|
|
|
func record(
|
|
kind: SFTPHistoryEntry.Kind, path: String, for hostID: Host.ID,
|
|
at date: Date = Date()
|
|
) {
|
|
let path = RemotePath.normalized(path)
|
|
do {
|
|
try repository.upsert(
|
|
SFTPHistoryEntry(hostID: hostID, kind: kind, path: path, visitedAt: date),
|
|
limit: Self.perHostLimit
|
|
)
|
|
storageError = nil
|
|
revision &+= 1
|
|
} catch {
|
|
storageError = error.localizedDescription
|
|
}
|
|
}
|
|
|
|
func delete(_ id: SFTPHistoryEntry.ID) {
|
|
do {
|
|
try repository.delete(id)
|
|
storageError = nil
|
|
revision &+= 1
|
|
} catch { storageError = error.localizedDescription }
|
|
}
|
|
|
|
func clear(for hostID: Host.ID) {
|
|
do {
|
|
try repository.clear(for: hostID)
|
|
storageError = nil
|
|
revision &+= 1
|
|
} catch { storageError = error.localizedDescription }
|
|
}
|
|
}
|