Desktop: downloads are written beside and put in place, not rewritten
Some checks are pending
CI / check (push) Waiting to run
CI / windows-build (push) Waiting to run
CI / macos-build (push) Waiting to run

On macOS (Apple silicon) Rodent IV build 2, downloaded over the 1.7 build, was killed
at its first start: the kernel keeps the signature of an executable that once ran, and
the file had been rewritten in place. The owner's Mac ran the same build fine from a
fresh file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-10-27 12:07:54 +03:00
parent fa2be527c6
commit 8e79a888ef
2 changed files with 25 additions and 1 deletions

View file

@ -228,13 +228,34 @@ fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result<PathBuf, Failure>
result
}
/// Downloads `url` into `to`, checking the size and the SHA-256 on the way.
/// Downloads `url` into `to`, checking the size and the SHA-256 on the way. The file is
/// written beside and put in place once checked: a new file, never the old one rewritten
/// (macOS on Apple silicon kills an executable rewritten in place after it once ran: it
/// keeps the old signature for that file).
pub fn fetch(
url: &str,
to: &Path,
asset: &Asset,
report: &dyn Fn(Stage),
cancel: &AtomicBool,
) -> Result<(), Failure> {
let mut part = to.as_os_str().to_owned();
part.push(".part");
let part = PathBuf::from(part);
let result = fetch_into(url, &part, asset, report, cancel)
.and_then(|()| std::fs::rename(&part, to).map_err(disk));
if result.is_err() {
let _ = std::fs::remove_file(&part);
}
result
}
fn fetch_into(
url: &str,
to: &Path,
asset: &Asset,
report: &dyn Fn(Stage),
cancel: &AtomicBool,
) -> Result<(), Failure> {
let mut response = ureq::get(url).call().map_err(|e| match e {
ureq::Error::StatusCode(code) => Failure::Server(code),