Skip to content

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

macOS: helpers get Homebrew's folders on their PATH (#659) (#662)

Ahmed Nefzaoui8200e91208a4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9f00aeb2..52491060 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- macOS: YouTube videos that need yt-dlp's JavaScript runtime load when MDM is opened from Finder or the Dock. MDM found Homebrew's yt-dlp, but the helpers it started didn't get Homebrew's folders on their PATH, so yt-dlp found neither Deno nor ffmpeg ("Requested format is not available"); they now look there too, after the folders of their own PATH ([#659](https://github.com/anefzaoui/misterdownloadmanager/issues/659)).
- A download handed over by the browser whose link the site refuses to MDM before sending anything (FileHippo's links answered **412 Precondition Failed**; a one-time link the browser has already used, or one tied to its session, answers 403, 404 or 410) goes on from the address the browser's own download of it had reached, once; if that is refused too, the link's own answer is the error shown. Its cookies go there only when it is the same site ([#630](https://github.com/anefzaoui/misterdownloadmanager/issues/630)).
- Raising a speed limit, or turning it off, applies at once: to a download's own limit (its progress window's **Speed Limiter** tab), the limit for one file and the limit for all downloads together. A connection already waiting its turn under the old limit sat out the wait the old limit gave it, many seconds at a low limit, before the new speed showed; it now counts what is left at the new limit, and ends its wait as soon as there is no limit ([#621](https://github.com/anefzaoui/misterdownloadmanager/issues/621)).
- **Download video**: a sound-only choice (MP3, Opus, FLAC, the original sound) saves in the Music category's folder and is listed under Music, as a playlist downloaded as sound only does; choosing a video again goes back to the Video folder. A folder you typed or picked in **Save to** stays as it is ([#611](https://github.com/anefzaoui/misterdownloadmanager/issues/611)).
diff --git a/ROADMAP.md b/ROADMAP.md
index bcc4aa39..a2d0b883 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -501,6 +501,8 @@ Bug fixes from the first days of 0.5.0, a Safari extension, and more file types.
These ship in the next version.
+- ✅ macOS: helpers opened from Finder find Homebrew's Deno and ffmpeg, so YouTube formats
+ load ([#659](https://github.com/anefzaoui/misterdownloadmanager/issues/659))
- ✅ The website is named as the official one in the README, the browser add-on and the
site's data for search engines
- ✅ Left click on the tray icon toggles the main window (on Windows also with the icon under
diff --git a/crates/tools/src/proc.rs b/crates/tools/src/proc.rs
index 4517d668..a19f7630 100644
--- a/crates/tools/src/proc.rs
+++ b/crates/tools/src/proc.rs
@@ -703,10 +703,24 @@ fn js_runtime(dirs: &[PathBuf], home: Option<&Path>) -> Option<(&'static str, Pa
/// left out; one reached through a junction or link is given as the folder it leads to, so the
/// helper crosses no mount point on its way, even when Windows holds the helper to stricter
/// rules than MDM. Every other folder stays as it was written.
+///
+/// On Linux and macOS the package managers' folders follow, when the PATH lacks them (#659): a
+/// helper found there ([`crate::system`]) looks there for its own tools too (yt-dlp for Deno
+/// and ffmpeg), even when MDM was opened from Finder, whose PATH has no Homebrew.
fn usable_dirs(path: &std::ffi::OsStr) -> Vec<PathBuf> {
- std::env::split_paths(path)
+ #[allow(unused_mut)]
+ let mut dirs: Vec<PathBuf> = std::env::split_paths(path)
.filter_map(|dir| usable_dir(&dir))
- .collect()
+ .collect();
+ #[cfg(unix)]
+ for extra in crate::system::PACKAGE_DIRS.map(PathBuf::from) {
+ if !dirs.contains(&extra)
+ && let Some(dir) = usable_dir(&extra)
+ {
+ dirs.push(dir);
+ }
+ }
+ dirs
}
fn usable_dir(dir: &Path) -> Option<PathBuf> {
@@ -1395,19 +1409,60 @@ mod tests {
std::fs::create_dir_all(&b).unwrap();
std::fs::write(&file, b"").unwrap();
let join = |dirs: &[&PathBuf]| std::env::join_paths(dirs).unwrap();
+ // What the helper gets: those, then (on Linux and macOS) the package folders (#659).
+ let given = |dirs: &[&PathBuf]| {
+ #[allow(unused_mut)]
+ let mut all: Vec<PathBuf> = dirs.iter().map(|d| d.to_path_buf()).collect();
+ #[cfg(unix)]
+ all.extend(
+ crate::system::PACKAGE_DIRS
+ .map(PathBuf::from)
+ .into_iter()
+ .filter(|d| d.is_dir()),
+ );
+ std::env::join_paths(all).unwrap()
+ };
let plain = join(&[&b, &a]);
- assert_eq!(child_path(&plain).unwrap(), plain);
+ assert_eq!(child_path(&plain).unwrap(), given(&[&b, &a]));
assert_eq!(
child_path(&join(&[&gone, &b, &file, &a])).unwrap(),
- join(&[&b, &a])
+ given(&[&b, &a])
);
let mut cmd = Command::new("x");
cmd.env("PATH", join(&[&a, &gone]));
with_usable_path(&mut cmd);
- let given: Vec<_> = cmd.get_envs().filter(|(k, _)| *k == "PATH").collect();
- assert_eq!(given, [(std::ffi::OsStr::new("PATH"), Some(a.as_os_str()))]);
+ let got: Vec<_> = cmd.get_envs().filter(|(k, _)| *k == "PATH").collect();
+ let want = given(&[&a]);
+ assert_eq!(
+ got,
+ [(std::ffi::OsStr::new("PATH"), Some(want.as_os_str()))]
+ );
+ }
+
+ /// #659: MDM opened from Finder has no Homebrew on its PATH, yet finds yt-dlp there; the
+ /// helper gets the package folders after its own, once each, so yt-dlp finds Deno and
+ /// ffmpeg where Homebrew put them.
+ #[cfg(unix)]
+ #[test]
+ fn a_helper_gets_the_package_folders_after_its_path() {
+ let root = tempfile::tempdir().unwrap();
+ let own = root.path().join("own");
+ std::fs::create_dir_all(&own).unwrap();
+ let usr_bin = PathBuf::from("/usr/bin");
+
+ let dirs = usable_dirs(&std::env::join_paths([&own]).unwrap());
+ assert_eq!(dirs[0], own, "the PATH's own folders first");
+ assert!(dirs.contains(&usr_bin), "{dirs:?}");
+ for d in crate::system::PACKAGE_DIRS.map(PathBuf::from) {
+ assert_eq!(dirs.contains(&d), d.is_dir(), "{d:?} in {dirs:?}");
+ }
+
+ // Already on the PATH: kept where it was, not added again.
+ let dirs = usable_dirs(&std::env::join_paths([&usr_bin, &own]).unwrap());
+ assert_eq!(dirs[..2], [usr_bin.clone(), own]);
+ assert_eq!(dirs.iter().filter(|d| **d == usr_bin).count(), 1);
}
/// #508 as it happened: Windows refuses a junction to a process held to Redirection Guard
diff --git a/crates/tools/src/system.rs b/crates/tools/src/system.rs
index c9b097ef..a0b7733f 100644
--- a/crates/tools/src/system.rs
+++ b/crates/tools/src/system.rs
@@ -5,14 +5,18 @@ use std::path::{Path, PathBuf};
use crate::Installed;
-/// PATH first, then the usual package-manager folders: an app opened from the Dock may not
-/// inherit the shell's PATH. Discovery only reads metadata, never starts a helper on the UI thread.
+/// The usual package-manager folders (Homebrew on Apple silicon and on Intel, then the system's):
+/// an app opened from the Dock or Finder may not inherit the shell's PATH, so helpers are looked
+/// for there too, and a helper found there gets them on its PATH for its own tools (#659).
+pub(crate) const PACKAGE_DIRS: [&str; 3] = ["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin"];
+
+/// PATH first, then [`PACKAGE_DIRS`]. Discovery only reads metadata, never starts a helper on
+/// the UI thread.
pub(crate) fn installed(name: &str) -> Option<Installed> {
let path = std::env::var_os("PATH").unwrap_or_default();
find_in(
name,
- std::env::split_paths(&path)
- .chain(["/opt/homebrew/bin", "/usr/local/bin", "/usr/bin"].map(PathBuf::from)),
+ std::env::split_paths(&path).chain(PACKAGE_DIRS.map(PathBuf::from)),
)
.map(|exe| Installed {
version: crate::SYSTEM.into(),