fix(loader): stage prepared images in per-writer files
write_if_changed used a shared <hash>.tmp file, so two concurrent cold launches of the same image could truncate each other's staging bytes or fail the rename after the other had published. Move publication into a portable module that stages under a unique pid/sequence name and removes it on failure. Two hermetic tests cover concurrent publishers and a failed rename. (cherry picked from commit 1aac20aa8fd97237053c985b942225d54c0194a7)
This commit is contained in:
1 parent
e7b97d9bf6
commit
b0f38b4a0c
3 files changed
+79
-7
No files matched your search
@@ -183,13 +183,8 @@ impl ImportResolver for WithTitleDlls<'_> {
|
||||
}
|
||||
|
||||
fn write_if_changed(path: &Path, bytes: &[u8]) -> Result<()> {
|
||||
if std::fs::read(path).is_ok_and(|existing| existing == bytes) {
|
||||
return Ok(());
|
||||
}
|
||||
let tmp = path.with_extension("tmp");
|
||||
std::fs::write(&tmp, bytes).with_context(|| format!("writing {}", tmp.display()))?;
|
||||
std::fs::rename(&tmp, path).with_context(|| format!("renaming to {}", path.display()))?;
|
||||
Ok(())
|
||||
crate::publish::write_if_changed(path, bytes)
|
||||
.with_context(|| format!("publishing {}", path.display()))
|
||||
}
|
||||
|
||||
impl LoadedImage {
|
||||
|
||||
Reference in new issue
Block a user