-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMutagenConvert.swift
82 lines (79 loc) · 2.66 KB
/
MutagenConvert.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// swiftlint:disable:next cyclomatic_complexity
func convertSessionStatus(status: Synchronization_Status) -> FileSyncStatus {
switch status {
case .disconnected:
.error(.disconnected)
case .haltedOnRootEmptied:
.error(.haltedOnRootEmptied)
case .haltedOnRootDeletion:
.error(.haltedOnRootDeletion)
case .haltedOnRootTypeChange:
.error(.haltedOnRootTypeChange)
case .waitingForRescan:
.error(.waitingForRescan)
case .connectingAlpha:
.working(.connectingAlpha)
case .connectingBeta:
.working(.connectingBeta)
case .scanning:
.working(.scanning)
case .reconciling:
.working(.reconciling)
case .stagingAlpha:
.working(.stagingAlpha)
case .stagingBeta:
.working(.stagingBeta)
case .transitioning:
.working(.transitioning)
case .saving:
.working(.saving)
case .watching:
.ok
case .UNRECOGNIZED:
.unknown
}
}
func accumulateErrors(from state: Synchronization_State) -> [FileSyncError] {
var errors: [FileSyncError] = []
if !state.lastError.isEmpty {
errors.append(.generic(state.lastError))
}
for problem in state.alphaState.scanProblems {
errors.append(.problem(.local, .scan, path: problem.path, error: problem.error))
}
for problem in state.alphaState.transitionProblems {
errors.append(.problem(.local, .transition, path: problem.path, error: problem.error))
}
for problem in state.betaState.scanProblems {
errors.append(.problem(.remote, .scan, path: problem.path, error: problem.error))
}
for problem in state.betaState.transitionProblems {
errors.append(.problem(.remote, .transition, path: problem.path, error: problem.error))
}
return errors
}
func humanReadableBytes(_ bytes: UInt64) -> String {
ByteCountFormatter().string(fromByteCount: Int64(bytes))
}
extension Prompting_HostResponse {
func ensureValid(first: Bool, allowPrompts: Bool) throws(DaemonError) {
if first {
if identifier.isEmpty {
throw .invalidGrpcResponse("empty prompter identifier")
}
if isPrompt {
throw .invalidGrpcResponse("unexpected message type specification")
}
if !message.isEmpty {
throw .invalidGrpcResponse("unexpected message")
}
} else {
if !identifier.isEmpty {
throw .invalidGrpcResponse("unexpected prompter identifier")
}
if isPrompt, !allowPrompts {
throw .invalidGrpcResponse("disallowed prompt message type")
}
}
}
}