fix(portable): retry failed stale branding cleanup

Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
fufesou
2026-08-12 17:57:44 +08:00
parent 9dae15e523
commit d0da2441e5

View File

@@ -123,8 +123,16 @@ fn resolve_within(dir: &Path, relative: &str) -> Option<PathBuf> {
// would otherwise linger in an existing extraction and keep being used. The wipe // would otherwise linger in an existing extraction and keep being used. The wipe
// cannot cover this: it is keyed on the packer's build timestamp, which is now the // cannot cover this: it is keyed on the packer's build timestamp, which is now the
// same for every customer of a release. // same for every customer of a release.
fn remove_dropped_package_files(dir: &Path, current: &[String]) { fn remove_dropped_package_files_with<F>(
dir: &Path,
current: &[String],
mut remove_file: F,
) -> Vec<String>
where
F: FnMut(&Path) -> std::io::Result<()>,
{
let keep: std::collections::HashSet<String> = current.iter().map(|p| normalized(p)).collect(); let keep: std::collections::HashSet<String> = current.iter().map(|p| normalized(p)).collect();
let mut failed = Vec::new();
for previous in previous_package_files(dir) { for previous in previous_package_files(dir) {
if keep.contains(&normalized(&previous)) { if keep.contains(&normalized(&previous)) {
continue; continue;
@@ -134,9 +142,17 @@ fn remove_dropped_package_files(dir: &Path, current: &[String]) {
}; };
if path.is_file() { if path.is_file() {
println!("removing dropped {}", previous); println!("removing dropped {}", previous);
let _ = std::fs::remove_file(path); if let Err(error) = remove_file(&path) {
eprintln!("failed to remove dropped {}: {}", previous, error);
failed.push(previous);
}
} }
} }
failed
}
fn remove_dropped_package_files(dir: &Path, current: &[String]) -> Vec<String> {
remove_dropped_package_files_with(dir, current, |path| std::fs::remove_file(path))
} }
fn setup( fn setup(
@@ -167,11 +183,12 @@ fn setup(
} }
std::fs::remove_dir_all(&dir).ok(); std::fs::remove_dir_all(&dir).ok();
} }
remove_dropped_package_files(&dir, &reader.package_paths); let mut metadata_paths = reader.package_paths.clone();
metadata_paths.extend(remove_dropped_package_files(&dir, &reader.package_paths));
for file in reader.files.iter() { for file in reader.files.iter() {
file.write_to_file(&dir); file.write_to_file(&dir);
} }
write_meta(&dir, ts, &reader.package_paths); write_meta(&dir, ts, &metadata_paths);
#[cfg(windows)] #[cfg(windows)]
win::copy_runtime_broker(&dir); win::copy_runtime_broker(&dir);
#[cfg(linux)] #[cfg(linux)]