mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-12-02 03:00:05 +08:00
refactor(profile-store): reuse the journal install scratch file
This commit is contained in:
@@ -27,6 +27,7 @@ const BODY_NEXT: &str = "body.next";
|
||||
const INDEX_NEXT: &str = "index.next";
|
||||
const DECISION_NEXT: &str = "decision.next";
|
||||
const DECISION_BUILDING: &str = "decision.building";
|
||||
const APPLY: &str = "body.apply";
|
||||
|
||||
type Result<T> = std::result::Result<T, StoreError>;
|
||||
|
||||
@@ -158,16 +159,15 @@ impl Session {
|
||||
checkpoint("decision-synced")?;
|
||||
self.install(checkpoint)
|
||||
})();
|
||||
match published {
|
||||
Err(error) => CommitOutcome::NeedsRecovery(error),
|
||||
Ok(InstallOutcome::Installed) => match self.disarm_and_clean(checkpoint) {
|
||||
Ok(()) => CommitOutcome::Committed,
|
||||
Err(error) => CommitOutcome::CommittedCleanupPending(error),
|
||||
},
|
||||
Ok(InstallOutcome::Reverted(rejection)) => match self.disarm_and_clean(checkpoint) {
|
||||
Ok(()) => CommitOutcome::Retryable(rejection),
|
||||
Err(error) => CommitOutcome::NeedsRecovery(error),
|
||||
},
|
||||
let installed = match published {
|
||||
Ok(installed) => installed,
|
||||
Err(error) => return CommitOutcome::NeedsRecovery(error),
|
||||
};
|
||||
match (installed, self.disarm_and_clean(checkpoint)) {
|
||||
(InstallOutcome::Installed, Ok(())) => CommitOutcome::Committed,
|
||||
(InstallOutcome::Installed, Err(error)) => CommitOutcome::CommittedCleanupPending(error),
|
||||
(InstallOutcome::Reverted(rejection), Ok(())) => CommitOutcome::Retryable(rejection),
|
||||
(InstallOutcome::Reverted(_), Err(error)) => CommitOutcome::NeedsRecovery(error),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,6 +277,7 @@ impl Session {
|
||||
let profiles_dir = self.root.join(PROFILES);
|
||||
let body_path = profiles_dir.join(&decision.file);
|
||||
let index_path = self.root.join(INDEX);
|
||||
let apply = journal.join(APPLY);
|
||||
let body_installed = verify_live(&body_path, decision.old_body_digest, decision.body_digest)?;
|
||||
let index_installed = verify_live(&index_path, Some(decision.old_index_digest), decision.index_digest)?;
|
||||
let can_revert_new_body = decision.old_body_digest.is_none()
|
||||
@@ -293,7 +294,6 @@ impl Session {
|
||||
// Equality alone does not establish durability of a prior in-place edit.
|
||||
platform::sync_file(&body_path)?;
|
||||
} else {
|
||||
let apply = journal.join("body.apply");
|
||||
remove_file_if_exists(&apply)?;
|
||||
copy_verified(&body_next, &apply, decision.body_digest)?;
|
||||
platform::replace(&apply, &body_path).map_err(|source| StoreError::PathIo {
|
||||
@@ -329,7 +329,7 @@ impl Session {
|
||||
if index_installed {
|
||||
platform::sync_file(&index_path)?;
|
||||
} else {
|
||||
let apply = journal.join("index.apply");
|
||||
// The body rename consumed the scratch file. Replay can discard it at either step.
|
||||
remove_file_if_exists(&apply)?;
|
||||
write_new(&apply, &index, Some(index_permissions))?;
|
||||
platform::replace(&apply, &index_path).map_err(|source| StoreError::PathIo {
|
||||
@@ -363,8 +363,8 @@ impl Session {
|
||||
DECISION_BUILDING,
|
||||
BODY_NEXT,
|
||||
INDEX_NEXT,
|
||||
"body.apply",
|
||||
"index.apply",
|
||||
APPLY,
|
||||
"index.apply", // Older v1 journals used a separate scratch file for the index.
|
||||
] {
|
||||
remove_file_if_exists(&journal.join(name))?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user