Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Updated AppImage takes the release file name (#3538) (#3658)

rlartotc7e53899af65
diff --git a/crates/ui-egui/src/update/install.rs b/crates/ui-egui/src/update/install.rs
index ead6907e19..8a88fafb29 100644
--- a/crates/ui-egui/src/update/install.rs
+++ b/crates/ui-egui/src/update/install.rs
@@ -214,7 +214,29 @@ pub fn run(
if actual != expected {
return Err(cleanup(format!("{} doesn't match {SUMS} (got {actual}, expected {expected}); it was deleted", asset.name)));
}
- apply(method, &part).map_err(cleanup)
+ let outcome = apply(method, &part).map_err(cleanup)?;
+ Ok(match (method, outcome) {
+ // Zsync-based tools (Gearlever, AppImageUpdate) find the update data by the release's file name.
+ (Method::AppImage(_), Outcome::Restart(placed)) => {
+ let named = release_named(&placed, release.version(), arch);
+ // A failed rename leaves the new AppImage under its old name: it still works.
+ Outcome::Restart(if named != placed && std::fs::rename(&placed, &named).is_ok() { named } else { placed })
+ }
+ (_, outcome) => outcome,
+ })
+}
+
+/// Where an AppImage called `path` goes once it holds `version`: if its name is a release name
+/// (`solidcraft-<version>-linux-<arch>.AppImage`, or the old `solvecraft-` one), the new release's name
+/// in the same folder; any other name (renamed by the user, or without a version) is kept.
+pub fn release_named(path: &Path, version: &str, arch: &str) -> PathBuf {
+ let name = path.file_name().map(|n| n.to_string_lossy().to_ascii_lowercase()).unwrap_or_default();
+ let rest = name.strip_prefix("solidcraft-").or_else(|| name.strip_prefix("solvecraft-"));
+ if rest.is_some_and(|r| r.starts_with(|c: char| c.is_ascii_digit()) && r.contains("-linux-") && r.ends_with(".appimage")) {
+ path.with_file_name(format!("solidcraft-{}-linux-{arch}.AppImage", version.trim_start_matches('v')))
+ } else {
+ path.to_path_buf()
+ }
}
/// Put a verified package in place.
diff --git a/crates/ui-egui/src/update/install_tests.rs b/crates/ui-egui/src/update/install_tests.rs
index 3829203db3..bacef38c48 100644
--- a/crates/ui-egui/src/update/install_tests.rs
+++ b/crates/ui-egui/src/update/install_tests.rs
@@ -218,3 +218,31 @@ fn windows_installer_is_followed_by_the_new_version() {
);
assert!(out.iter().any(|a| a == "-Command"));
}
+
+#[test]
+fn an_updated_appimage_takes_the_release_file_name() {
+ let new = |p: &str| release_named(Path::new(p), "v0.17.0", "x86_64");
+ assert_eq!(new("/a/solidcraft-0.16.2-linux-x86_64.AppImage"), Path::new("/a/solidcraft-0.17.0-linux-x86_64.AppImage"));
+ assert_eq!(new("/a/solvecraft-0.9.0-linux-x86_64.AppImage"), Path::new("/a/solidcraft-0.17.0-linux-x86_64.AppImage"));
+ assert_eq!(new("/a/SolidCraft.AppImage"), Path::new("/a/SolidCraft.AppImage"), "a name the user chose");
+ assert_eq!(new("/a/solidcraft-linux-x86_64.AppImage"), Path::new("/a/solidcraft-linux-x86_64.AppImage"), "no version in it");
+ assert_eq!(new("/a/solidcraft-0.16.2-linux-x86_64.AppImage.bak"), Path::new("/a/solidcraft-0.16.2-linux-x86_64.AppImage.bak"));
+
+ // End to end: the old versioned file is gone, the new one has the release's name and works.
+ let dir = scratch("appimage-name");
+ let old = dir.join("solidcraft-9.9.8-linux-x86_64.AppImage");
+ std::fs::write(&old, b"old version").unwrap();
+ let name = "solidcraft-linux-x86_64.AppImage";
+ let content = b"new version".to_vec();
+ let r = release_with(&[(name, content.len()), (SUMS, 100)]);
+ let sums = format!("{} {name}\n", hex(&content));
+ let n = net(vec![(name.into(), content.clone()), (SUMS.into(), sums.into_bytes())]);
+ let kind = InstallKind::AppImage(old.clone());
+ let out = run(&r, &kind, &Method::AppImage(old.clone()), "x86_64", &n, &dir, &Progress::default()).unwrap();
+ let want = dir.join("solidcraft-9.9.9-linux-x86_64.AppImage");
+ assert_eq!(out, Outcome::Restart(want.clone()));
+ assert_eq!(std::fs::read(&want).unwrap(), content);
+ assert!(!old.exists());
+ assert_eq!(std::fs::read_dir(&dir).unwrap().count(), 1, "nothing else is left behind");
+ let _ = std::fs::remove_dir_all(&dir);
+}
diff --git a/docs/book/src/guide/updates.md b/docs/book/src/guide/updates.md
index 0444c2f81b..fa77b88027 100644
--- a/docs/book/src/guide/updates.md
+++ b/docs/book/src/guide/updates.md
@@ -28,7 +28,7 @@ Where SolidCraft can replace itself safely, the window also has **Update now**:
| Installed as | Update now does |
|---|---|
-| AppImage | Downloads the new AppImage next to the old one, verifies it, renames it over the old file and offers **Restart now** |
+| AppImage | Downloads the new AppImage next to the old one, verifies it, renames it over the old file and offers **Restart now**; a file named like a release (`solidcraft-<version>-linux-<arch>.AppImage`) takes the new release's name, so tools such as Gearlever keep finding its update data, and any other name is kept |
| Windows installer (`.msi`) | **Install (closes SolidCraft)**: downloads and verifies the `.msi`, closes SolidCraft (asking about unsaved designs first) and starts the installer |
| Windows portable `.zip` or `.exe` | Downloads and verifies the package, swaps in the new `solidcraft.exe` (and `solidcraft-cli.exe`) and offers **Restart now**; the old file is removed at the next start |
| macOS | **Download and open**: downloads and verifies the `.dmg` and opens it; drag SolidCraft to Applications to replace the old copy |