Skip to content

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

A save folder relative to the home folder is found where it really is (#428)

Ahmed Nefzaouiaefa9381886e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 24823c9c..5189e471 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
### Fixed
+- A save folder shown as `Downloads/Video` could be taken literally, asking to create it in the wrong place or failing with "Read-only file system" on macOS.
- macOS: **Download video** no longer stops with a Python error and a "Python.framework is damaged" alert on a copy of MDM downloaded by a browser ([#330](https://github.com/anefzaoui/misterdownloadmanager/issues/330), [#339](https://github.com/anefzaoui/misterdownloadmanager/issues/339)). MDM now installs yt-dlp's folder build, which it unpacks once and checks against yt-dlp's signed list, instead of the single-program build that unpacks Python afresh at every start. The video window then offers to install it in place of a copy that came with an earlier version.
- Browser link import: tighter handling of site data.
- Crash reports: a freeze that was over before its snapshot was taken says so, instead of calling it a deadlock in code that was only waiting for events ([#355](https://github.com/anefzaoui/misterdownloadmanager/issues/355)).
diff --git a/ROADMAP.md b/ROADMAP.md
index 0b393c9c..3c36f896 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -134,6 +134,7 @@ Everything below ships together, in version 0.5.0.
- ✅ Far more file types taken by default: AI models and datasets, 3D and CAD, design and camera
RAW, ebooks, Office, disk images and split archives; a list never edited gains them
([#382](https://github.com/anefzaoui/misterdownloadmanager/issues/382))
+- ✅ A save folder relative to the home folder is found where it really is
- ✅ Browser link import: tighter handling of site data
- ✅ The extension asks for a newer MDM only when a whole release separates them, not over a
bug-fix version
diff --git a/crates/app/src/categories.rs b/crates/app/src/categories.rs
index 75b4b977..db0ff3d1 100644
--- a/crates/app/src/categories.rs
+++ b/crates/app/src/categories.rs
@@ -381,6 +381,14 @@ pub fn restored_names() -> String {
#[cfg(test)]
mod tests {
+ // Whole paths on the system the tests run on.
+ const SONGS: &str = if cfg!(windows) {
+ r"E:\Songs"
+ } else {
+ "/mnt/Songs"
+ };
+ const ALL: &str = if cfg!(windows) { r"F:\All" } else { "/mnt/All" };
+
use super::*;
/// The category registry is the process's: its tests take turns.
@@ -407,7 +415,7 @@ mod tests {
let downloads = Path::new(r"C:\Users\u\Downloads");
apply(
&mut s,
- edit(Category::Music, "Songs", "MP3 FLAC", r"E:\Songs"),
+ edit(Category::Music, "Songs", "MP3 FLAC", SONGS),
downloads,
);
assert_eq!(Category::Music.label(), "Songs");
@@ -423,10 +431,7 @@ mod tests {
Category::General,
"WAV was taken off"
);
- assert_eq!(
- s.category_dir(Category::Music, downloads),
- Path::new(r"E:\Songs")
- );
+ assert_eq!(s.category_dir(Category::Music, downloads), Path::new(SONGS));
assert_eq!(
Category::Music.default_folder(downloads),
downloads.join("Music"),
@@ -486,7 +491,7 @@ mod tests {
},
downloads,
);
- s.set_category_dir(Category::General, Some(r"F:\All".into()));
+ s.set_category_dir(Category::General, Some(ALL.into()));
restore(&mut s);
assert!(!Category::Video.deleted());
assert_eq!(Category::Video.label(), "Video");
@@ -495,10 +500,7 @@ mod tests {
s.category_dir(Category::Video, downloads),
downloads.join("Video")
);
- assert_eq!(
- s.category_dir(Category::General, downloads),
- Path::new(r"F:\All")
- );
+ assert_eq!(s.category_dir(Category::General, downloads), Path::new(ALL));
assert!(Category::all().contains(&books));
s = Settings::default();
s.publish_categories();
diff --git a/crates/app/src/gallerydlg.rs b/crates/app/src/gallerydlg.rs
index be0fcdc6..205c5bfb 100644
--- a/crates/app/src/gallerydlg.rs
+++ b/crates/app/src/gallerydlg.rs
@@ -105,7 +105,7 @@ impl GalleryDialog {
self.tool = None;
self.checked = None;
}
- let folder = PathBuf::from(self.folder.trim());
+ let folder = crate::dialogs::resolve_path(&self.folder);
match crate::dialogs::ensure_folder(ctx, &mut self.asking, out, &folder) {
Outcome::Open => Outcome::Open,
Outcome::Closed => Outcome::Closed,
diff --git a/crates/app/src/model.rs b/crates/app/src/model.rs
index eea14c23..fac6d7e6 100644
--- a/crates/app/src/model.rs
+++ b/crates/app/src/model.rs
@@ -321,7 +321,8 @@ pub fn category_folder(cat: Category, downloads: &Path, dirs: &[(String, String)
let key = cat.key();
dirs.iter()
.find(|(c, _)| *c == *key)
- .map(|(_, d)| PathBuf::from(d))
+ // A folder may be saved as shown, relative to the user's home.
+ .map(|(_, d)| crate::dialogs::resolve_path(d))
.unwrap_or_else(|| cat.folder(downloads))
}
@@ -1087,6 +1088,21 @@ mod size_tests {
mod tests {
use super::*;
+ #[test]
+ fn a_folder_saved_as_shown_is_under_home() {
+ let home = dirs::home_dir().unwrap();
+ let dirs = vec![("Video".to_owned(), "Downloads/Video".to_owned())];
+ let got = category_folder(Category::Video, Path::new("x"), &dirs);
+ assert_eq!(got, home.join("Downloads/Video"));
+ assert!(got.is_absolute());
+ let whole = home.join("Elsewhere").display().to_string();
+ let dirs = vec![("Video".to_owned(), whole.clone())];
+ assert_eq!(
+ category_folder(Category::Video, Path::new("x"), &dirs),
+ PathBuf::from(whole)
+ );
+ }
+
#[test]
fn categories() {
assert_eq!(Category::of("a.ZIP"), Category::Compressed);
diff --git a/crates/app/src/torrentdlg.rs b/crates/app/src/torrentdlg.rs
index 7df5c161..589d9ea8 100644
--- a/crates/app/src/torrentdlg.rs
+++ b/crates/app/src/torrentdlg.rs
@@ -374,7 +374,7 @@ impl TorrentDialog {
winui::BG(),
|ui, o| self.body(ui, o, rt),
);
- let folder = PathBuf::from(self.folder.trim());
+ let folder = crate::dialogs::resolve_path(&self.folder);
let out = crate::dialogs::ensure_folder(ctx, &mut self.asking, out, &folder);
// Then: files of the torrent's names already there would be written into (#40).
let meta = &self.meta;
@@ -405,7 +405,7 @@ impl TorrentDialog {
Outcome::Done(TorrentAdd {
category: category_of(&meta),
meta,
- dir: PathBuf::from(self.folder.trim()),
+ dir: crate::dialogs::resolve_path(&self.folder),
files,
start_now: self.start_now.unwrap_or(true),
from_magnet: self.from_magnet,
@@ -637,7 +637,7 @@ impl TorrentDialog {
self.folder_edited = true;
}
if let Some(m) = &self.meta {
- let goes = m.folder_in(&PathBuf::from(self.folder.trim()));
+ let goes = m.folder_in(&crate::dialogs::resolve_path(&self.folder));
let s = crate::i18n::fmt(
// i18n: {folder} = the folder the torrent's files are saved in
crate::i18n::t("Files go to: {folder}"),
diff --git a/crates/app/src/videodlg.rs b/crates/app/src/videodlg.rs
index 02989a06..7d91341d 100644
--- a/crates/app/src/videodlg.rs
+++ b/crates/app/src/videodlg.rs
@@ -394,7 +394,7 @@ impl VideoDialog {
self.set_video(v);
}
}
- let folder = PathBuf::from(self.folder.trim());
+ let folder = crate::dialogs::resolve_path(&self.folder);
let out = crate::dialogs::ensure_folder(ctx, &mut self.asking, out, &folder);
// A playlist's videos, each its own download.
if let (Some(list), Outcome::Done(())) = (&self.list, &out) {
@@ -422,7 +422,7 @@ impl VideoDialog {
Outcome::Done(VideoOut::One(VideoAdd {
page,
selector: c.selector.clone(),
- dest: PathBuf::from(self.folder.trim()).join(name),
+ dest: crate::dialogs::resolve_path(&self.folder).join(name),
size: c.size,
start_now: self.start_now.unwrap_or(true),
context: self.context(),