Skip to content

misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux

Update now on Linux asks the package manager which package MDM is (#271)

Ahmed Nefzaouie512b2f93e78
diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml
index e6f9da3f..8efde001 100644
--- a/.github/ISSUE_TEMPLATE/bug.yml
+++ b/.github/ISSUE_TEMPLATE/bug.yml
@@ -39,7 +39,7 @@ body:
id: install
attributes:
label: Installed with
- description: "The installer (setup.exe), The portable zip, The plain zip, The .dmg, The AppImage, The .deb, The .rpm, The .tar.gz or Built from source."
+ description: "The installer (setup.exe), The portable zip, The plain zip, The .dmg, The AppImage, The .deb, The .rpm, The .tar.gz, Another package manager or Built from source."
placeholder: The installer (setup.exe)
validations:
required: true
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4781652a..0439c804 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -587,6 +587,12 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- **Update now on Linux asks the package manager which package MDM is**: a copy in /usr/bin
+ was taken for the .deb on a Debian-like system and for the .rpm anywhere else, so a copy
+ installed with another package manager (pacman on Arch) would have fetched and opened an .rpm.
+ MDM now asks dpkg, rpm and pacman which one owns its program; the .deb and .rpm update as
+ before, and a copy of another package manager is left to the system's updates: Check for
+ updates shows the new version's notes and says to update it there.
- **Linux: menus open under their title on tiling compositors**
([#267](https://github.com/anefzaoui/misterdownloadmanager/issues/267)): under sway (through
XWayland, MDM's default in a Wayland session), the menu bar's menus, their submenus, the
diff --git a/ROADMAP.md b/ROADMAP.md
index 2a8493e8..f9b4c338 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -13,6 +13,8 @@ Everything below ships together, in one release, as version 0.3.0.
### Done
+- ✅ Linux: Update now asks the package manager which package MDM is; a copy installed by
+ another package manager (pacman) is left to the system's updates, with a plain message
- ✅ Linux: the guide says what uninstalling leaves in each user's home folder (the browsers' host
files, the list and settings) and how to remove it; a package can't
([#266](https://github.com/anefzaoui/misterdownloadmanager/issues/266))
diff --git a/crates/app/src/help.rs b/crates/app/src/help.rs
index 1070a1e5..0e7f702d 100644
--- a/crates/app/src/help.rs
+++ b/crates/app/src/help.rs
@@ -405,11 +405,31 @@ impl Updates {
right,
"update-line",
);
- let have = crate::i18n::fmt(
- crate::i18n::t("You have version {version}."),
- &[("version", VERSION)],
+ // A package of another package manager (pacman, …): that one updates it.
+ let have = if install == mdm_tools::update::Install::System {
+ crate::i18n::fmt(
+ // i18n: Check for updates, under the new version's line, when MDM was installed by the Linux system's package manager (pacman, ...), which MDM can't update itself
+ crate::i18n::t(
+ "You have version {version}, from your system's package manager: update it there.",
+ ),
+ &[("version", VERSION)],
+ )
+ } else {
+ crate::i18n::fmt(
+ crate::i18n::t("You have version {version}."),
+ &[("version", VERSION)],
+ )
+ };
+ winui::fit(
+ ui,
+ &p,
+ o.x + 11.0,
+ o.y + 42.0,
+ &have,
+ winui::MUTED(),
+ right,
+ "update-have",
);
- winui::text(&p, o.x + 11.0, o.y + 42.0, &have, winui::MUTED());
winui::text(
&p,
o.x + 11.0,
@@ -443,10 +463,12 @@ impl Updates {
crate::update::asset_for(install, &rel.version, &rel.assets)
.filter(|_| !matches!(self.status, Some(UpdateStatus::Failed(_))))
});
+ // Another package manager's copy: no Update now nor Download, the notes only.
+ let managed = install == mdm_tools::update::Install::System;
let close_label = if self.job.is_some() {
// i18n: button: stop downloading the update
crate::i18n::mark("Cancel")
- } else if download.is_some() {
+ } else if download.is_some() && !managed {
// i18n: button: not now (download the update later)
crate::i18n::mark("Later")
} else {
@@ -456,7 +478,7 @@ impl Updates {
// version.
let first = if matches!(result, Some(Err(_))) {
Some("Retry")
- } else if download.is_some() {
+ } else if download.is_some() && !managed {
Some(if asset.is_some() {
"Update now"
} else {
@@ -559,7 +581,7 @@ impl Updates {
enter = false;
}
}
- if let Some(rel) = &download {
+ if let Some(rel) = download.as_ref().filter(|_| !managed) {
if let Some(asset) = asset {
let idle = self.job.is_none();
let kind = if idle {
diff --git a/crates/app/src/update.rs b/crates/app/src/update.rs
index 7438873f..927b0002 100644
--- a/crates/app/src/update.rs
+++ b/crates/app/src/update.rs
@@ -229,6 +229,7 @@ fn apply(install: Install, file: &Path) -> Result<Next, String> {
open::that_detached(file).map_err(|e| e.to_string())?;
Ok(Next::Opened)
}
+ Install::System => Err("installed by the system's package manager: update it there".into()),
Install::Source => Err("built from source: update it from the repository".into()),
}
}
diff --git a/crates/tools/src/update.rs b/crates/tools/src/update.rs
index af3b548e..d6c8d652 100644
--- a/crates/tools/src/update.rs
+++ b/crates/tools/src/update.rs
@@ -24,13 +24,22 @@ pub enum Install {
Rpm,
/// Linux, the plain programs.
TarGz,
+ /// Linux, a package of another package manager (pacman, …): that package manager updates
+ /// it, never MDM.
+ System,
/// Built here: never updated from a release.
Source,
}
impl Install {
- /// This copy's, from where its program is.
+ /// This copy's, from where its program is (found once: on Linux it asks the package
+ /// managers).
pub fn detect() -> Install {
+ static FOUND: std::sync::OnceLock<Install> = std::sync::OnceLock::new();
+ *FOUND.get_or_init(Install::find)
+ }
+
+ fn find() -> Install {
if cfg!(debug_assertions) {
return Install::Source;
}
@@ -59,14 +68,15 @@ impl Install {
if std::env::var_os("APPIMAGE").is_some() {
return Install::AppImage;
}
- if dir == Path::new("/usr/bin") {
- return if Path::new("/etc/debian_version").exists() {
- Install::Deb
- } else {
- Install::Rpm
- };
- }
- Install::TarGz
+ linux_package(&exe, &|tool, args| {
+ std::process::Command::new(tool)
+ .args(args)
+ .stdin(std::process::Stdio::null())
+ .stdout(std::process::Stdio::null())
+ .stderr(std::process::Stdio::null())
+ .status()
+ .is_ok_and(|s| s.success())
+ })
}
/// As the bug report form words it (.github/ISSUE_TEMPLATE/bug.yml, "Installed with").
@@ -80,11 +90,12 @@ impl Install {
Install::Deb => "The .deb",
Install::Rpm => "The .rpm",
Install::TarGz => "The .tar.gz",
+ Install::System => "Another package manager",
Install::Source => "Built from source",
}
}
- pub const ALL: [Install; 9] = [
+ pub const ALL: [Install; 10] = [
Install::Installer,
Install::PortableZip,
Install::PlainZip,
@@ -93,6 +104,7 @@ impl Install {
Install::Deb,
Install::Rpm,
Install::TarGz,
+ Install::System,
Install::Source,
];
@@ -113,7 +125,7 @@ impl Install {
Install::Deb => ("linux-x86_64", ".deb"),
Install::Rpm => ("linux-x86_64", ".rpm"),
Install::TarGz => ("linux-x86_64", ".tar.gz"),
- Install::Source => return Vec::new(),
+ Install::System | Install::Source => return Vec::new(),
};
let name = |tail: &str| format!("MisterDownloadManager-{version}-{tail}{ext}");
match self {
@@ -123,6 +135,28 @@ impl Install {
}
}
+/// Linux: which package manager's package `exe` is, asking each whether it owns the file
+/// (`owns(program, arguments)`: it ran and said yes). The .deb's (dpkg), the .rpm's (rpm), or
+/// another's (pacman; a program in /usr/bin none of them owns): those MDM leaves to the system's
+/// updates. Else the plain programs (.tar.gz), which MDM replaces itself. A path that isn't
+/// UTF-8 is never one of the packages'.
+fn linux_package(exe: &Path, owns: &dyn Fn(&str, &[&str]) -> bool) -> Install {
+ let Some(path) = exe.to_str() else {
+ return Install::TarGz;
+ };
+ if owns("dpkg-query", &["--search", path]) {
+ Install::Deb
+ } else if owns("rpm", &["--query", "--file", path]) {
+ Install::Rpm
+ } else if owns("pacman", &["--query", "--owns", path])
+ || exe.parent() == Some(Path::new("/usr/bin"))
+ {
+ Install::System
+ } else {
+ Install::TarGz
+ }
+}
+
/// The `.app` bundle a macOS program runs from (`X.app/Contents/MacOS/program`).
pub fn app_bundle(exe: &Path) -> Option<PathBuf> {
let bundle = exe.parent()?.parent()?.parent()?;
@@ -423,6 +457,41 @@ Connection: close
assert_eq!(labels.len(), Install::ALL.len());
}
+ /// Linux: the package manager that owns the program decides; the plain programs elsewhere.
+ #[test]
+ fn a_linux_copy_knows_its_package_manager() {
+ let owner = |who: &'static str| {
+ move |tool: &str, args: &[&str]| {
+ assert_eq!(args.last(), Some(&"/usr/bin/misterdownloadmanager"));
+ tool == who
+ }
+ };
+ let exe = Path::new("/usr/bin/misterdownloadmanager");
+ assert_eq!(linux_package(exe, &owner("dpkg-query")), Install::Deb);
+ assert_eq!(linux_package(exe, &owner("rpm")), Install::Rpm);
+ // An Arch package (pacman), or in /usr/bin with no package manager MDM knows: the
+ // system's.
+ assert_eq!(linux_package(exe, &owner("pacman")), Install::System);
+ assert_eq!(linux_package(exe, &owner("none")), Install::System);
+ // On Debian with rpm's tools installed too: still the .deb's.
+ let both = |tool: &str, _: &[&str]| tool == "dpkg-query" || tool == "rpm";
+ assert_eq!(linux_package(exe, &both), Install::Deb);
+ // The .tar.gz unpacked in the home folder, /opt or /usr/local: MDM's own to replace.
+ let nobody = |_: &str, _: &[&str]| false;
+ let home = Path::new("/home/me/MisterDownloadManager/misterdownloadmanager");
+ assert_eq!(linux_package(home, &nobody), Install::TarGz);
+ assert_eq!(
+ linux_package(Path::new("/opt/mdm/misterdownloadmanager"), &nobody),
+ Install::TarGz
+ );
+ assert_eq!(
+ linux_package(Path::new("/usr/local/bin/misterdownloadmanager"), &nobody),
+ Install::TarGz
+ );
+ // MDM updates neither another package manager's copy nor a build of its own.
+ assert!(Install::System.assets("1.0.0").is_empty());
+ }
+
#[test]
fn bundles_on_a_mac() {
let exe = Path::new(
diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md
index 2face3a0..a44bcffd 100644
--- a/docs/troubleshooting.md
+++ b/docs/troubleshooting.md
@@ -104,6 +104,7 @@ When there is one, **Update now** downloads it, checks it, puts it in place and
| Mac | Replaces the app in Applications. |
| Linux, the AppImage or the .tar.gz | Replaces the AppImage, or the programs in their folder. |
| Linux, the .deb or .rpm | Opens the checked package in your system's package installer, which asks for your password. |
+| Linux, another package manager's package (pacman, ...) | Nothing: the window says so, and your system's updates bring the new version. |
MDM installs an update only when the release's list of checksums is signed by MDM's release key and the file matches it; anything else is refused, and **Download** opens the [Releases](https://github.com/anefzaoui/misterdownloadmanager/releases) page instead. Updating this way starts with version 0.2.1: earlier versions open the Releases page.
diff --git a/i18n/en.tsv b/i18n/en.tsv
index 8b23b212..1f805ffe 100644
--- a/i18n/en.tsv
+++ b/i18n/en.tsv
@@ -3768,6 +3768,10 @@
#. {version} = a version number (keep the braces as they are)
You have the latest version of Mister Download Manager ({version}). You have the latest version of Mister Download Manager ({version}).
#. text in the Help menu's windows (About, updates, shortcuts, Tell a friend)
+#. Check for updates, under the new version's line, when MDM was installed by the Linux system's package manager (pacman, ...), which MDM can't update itself
+#. {version} = a version number (keep the braces as they are)
+ You have version {version}, from your system's package manager: update it there. You have version {version}, from your system's package manager: update it there.
+#. text in the Help menu's windows (About, updates, shortcuts, Tell a friend)
#. {version} = a version number (keep the braces as they are)
You have version {version}. You have version {version}.
#. text in extension.rs