fix(dtmm): Fix resetting mods

This commit is contained in:
Lucas Schwiderski 2023-02-28 21:18:32 +01:00
parent d5687ccae4
commit 7c7b9b5890
Signed by: lucas
GPG key ID: AA12679AAA6DF4D8

View file

@ -536,7 +536,8 @@ pub(crate) async fn deploy_mods(state: State) -> Result<()> {
#[tracing::instrument(skip(state))] #[tracing::instrument(skip(state))]
pub(crate) async fn reset_mod_deployment(state: State) -> Result<()> { pub(crate) async fn reset_mod_deployment(state: State) -> Result<()> {
let paths = [BUNDLE_DATABASE_NAME, BOOT_BUNDLE_NAME]; let boot_bundle_path = format!("{:016x}", Murmur64::hash(BOOT_BUNDLE_NAME.as_bytes()));
let paths = [BUNDLE_DATABASE_NAME, &boot_bundle_path];
let bundle_dir = state.game_dir.join("bundle"); let bundle_dir = state.game_dir.join("bundle");
tracing::info!("Resetting mod deployment in {}", bundle_dir.display()); tracing::info!("Resetting mod deployment in {}", bundle_dir.display());
@ -545,23 +546,36 @@ pub(crate) async fn reset_mod_deployment(state: State) -> Result<()> {
let path = bundle_dir.join(p); let path = bundle_dir.join(p);
let backup = bundle_dir.join(&format!("{}.bak", p)); let backup = bundle_dir.join(&format!("{}.bak", p));
tracing::debug!( let res = async {
"Copying from backup: {} -> {}", tracing::debug!(
backup.display(), "Copying from backup: {} -> {}",
path.display() backup.display(),
); path.display()
);
fs::copy(&backup, &path) fs::copy(&backup, &path)
.await .await
.wrap_err_with(|| format!("failed to '{}' restore from backup", p))?; .wrap_err_with(|| format!("failed to copy from '{}'", backup.display()))?;
tracing::debug!("Deleting backup: {}", backup.display(),); tracing::debug!("Deleting backup: {}", backup.display());
fs::remove_file(&backup) fs::remove_file(&backup)
.await .await
.wrap_err_with(|| format!("failed to remove backup '{}'", p))?; .wrap_err_with(|| format!("failed to remove '{}'", backup.display()))
}
.await;
if let Err(err) = res {
tracing::error!(
"Failed to restore '{}' from backup. You may need to verify game files. Error: {:?}",
&p,
err
);
}
} }
tracing::info!("Reset finished");
Ok(()) Ok(())
} }