diff --git a/CHANGELOG.md b/CHANGELOG.md index 4daa7e8..e4991ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes are listed here. Versions follow [Semantic Versioning](https ## [Unreleased] +- macOS: an engine downloaded over an older one (Rodent IV from 1.7 to 1.8) no longer + fails «it does not start on this computer»: a download is written beside and put in + place, never rewritten in place (Apple silicon kills an executable changed that way). - Desktop: a move can be taken back only in a blitz game against the computer; in rapid, classical and games without a clock «↶ Take back» (and Ctrl+Z) is gone. diff --git a/apps/desktop/src/engine_download.rs b/apps/desktop/src/engine_download.rs index ce48cdd..f0130a2 100644 --- a/apps/desktop/src/engine_download.rs +++ b/apps/desktop/src/engine_download.rs @@ -228,13 +228,34 @@ fn run(report: &dyn Fn(Stage), cancel: &AtomicBool) -> Result 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),