修复:加固 Windows 更新预检、提交点和可恢复的数据库回退流程
This commit is contained in:
@@ -55,9 +55,13 @@ public class SystemUpdateService {
|
||||
if (!enabled) return false;
|
||||
try {
|
||||
Map<?, ?> state = readMetadata("status.json");
|
||||
Map<?, ?> journal = readMetadata("journal.json");
|
||||
// 同一任务的持久提交记录优先于尚未成功刷新的进度提示。
|
||||
if (journal.get("operationId") instanceof String operationId && !operationId.isBlank()
|
||||
&& operationId.equals(state.get("operationId"))
|
||||
&& Set.of("complete", "rolledBack").contains(journal.get("phase"))) return false;
|
||||
if (state.get("state") instanceof String phase
|
||||
&& Set.of("backingUp", "installing", "restarting", "rollingBack").contains(phase)) return true;
|
||||
Map<?, ?> journal = readMetadata("journal.json");
|
||||
return journal.get("phase") instanceof String phase && Set.of("stopping", "installing").contains(phase);
|
||||
} catch (Exception failure) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{"protocol":2}
|
||||
@@ -60,4 +60,21 @@ class SystemUpdateServiceTest {
|
||||
Files.writeString(directory.resolve("status.json"), "broken JSON");
|
||||
assertTrue(service.maintenanceActive());
|
||||
}
|
||||
@Test
|
||||
void committedOperationOverridesItsStaleProgressButNotAnotherOperation(@TempDir Path root) throws Exception {
|
||||
var service = new SystemUpdateService(JsonMapper.builder().build(), root.toString(), false);
|
||||
var enabled = SystemUpdateService.class.getDeclaredField("enabled");
|
||||
enabled.setAccessible(true);
|
||||
enabled.setBoolean(service, true);
|
||||
var directory = Files.createDirectories(root.resolve(".runtime/update"));
|
||||
String current = "a".repeat(32), previous = "b".repeat(32);
|
||||
for (String phase : new String[]{"complete", "rolledBack"}) {
|
||||
Files.writeString(directory.resolve("status.json"), "{\"state\":\"restarting\",\"operationId\":\"" + current + "\"}");
|
||||
Files.writeString(directory.resolve("journal.json"), "{\"phase\":\"" + phase + "\",\"operationId\":\"" + current + "\"}");
|
||||
assertFalse(service.maintenanceActive(), phase);
|
||||
Files.writeString(directory.resolve("journal.json"), "{\"phase\":\"" + phase + "\",\"operationId\":\"" + previous + "\"}");
|
||||
assertTrue(service.maintenanceActive(), "another operation must not release maintenance");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user