misterdownloadmanager: The ultimate open-source, clean-room download manager written from scratch in pure Rust for Windows, Mac, and Linux
Rust bittorrent-clientdebriddownload-acceleratordownload-managerdownloadmanagereguifile-downloadergallery-dlidmidm-alternativeinternet-download-managerm3u8-downloadermagnetplaylist-downloaderreal-debridrusttorrent-clientvideo-downloaderyoutube-downloaderyt-dlp
macOS: downloads to a network volume no longer refused for 0 bytes free (#623) (#638)
Ahmed Nefzaoui5bfb9bb0211e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 12e374d5..eb3edfab 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -41,6 +41,7 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see- Windows: closing the window hides MDM in the notification area again when Windows keeps its icon among the hidden icons (behind ^), where a new icon goes. MDM took the icon for missing there and left the window in the taskbar instead; it now does that only when Windows has no icon of MDM's at all ([#545](https://github.com/anefzaoui/misterdownloadmanager/issues/545), [#534](https://github.com/anefzaoui/misterdownloadmanager/issues/534), [#527](https://github.com/anefzaoui/misterdownloadmanager/issues/527)).- The browser's **video button** over YouTube's thumbnail previews keeps one place, so it can be clicked: it moved to another corner when the preview showed its sound and captions buttons, back when they hid as the pointer reached it, and away again, and it followed the preview as it shrank. Over the same video it now only moves on to a free corner, never back, and it stays put while the pointer is on it ([#560](https://github.com/anefzaoui/misterdownloadmanager/issues/560)).- Chrome, Edge, Brave and the other Chromium browsers: a download the extension leaves to the browser keeps the name and folder another extension gives it (Save In's folders, or any extension's own download into a folder). The extension's answer for it counted as a name of its own, an empty one, and when the extension was the newest installed it won: the file landed in the Downloads folder, and the browser could warn of a conflict between the two extensions ([#578](https://github.com/anefzaoui/misterdownloadmanager/issues/578)).+- macOS: downloads to a network volume (a folder under `/Volumes` on an SMB, AFP or NFS share) start again. Each one was refused with "Not enough disk space ... 0 bytes free", however much the share had: macOS answers 0 when asked a network volume's space "for important usage" (the free space plus what the system can clear, as Finder counts it on the Mac's own disks), and MDM took that 0. On a network volume, or whenever that answer is 0, MDM now counts the free space the volume reports ([#623](https://github.com/anefzaoui/misterdownloadmanager/issues/623)).### Added- Options → General → **Customize MDM Download panels in browsers**: Export... and Import... for the sites the download button stays off, a plain text file with one site a line ([#424](https://github.com/anefzaoui/misterdownloadmanager/issues/424)).diff --git a/ROADMAP.md b/ROADMAP.mdindex 5fffe7cf..e55c48e1 100644--- a/ROADMAP.md+++ b/ROADMAP.md@@ -509,6 +509,8 @@ These ship in the next version.([#565](https://github.com/anefzaoui/misterdownloadmanager/issues/565))- ✅ A `funding.json` file, the open format funds use to find projects and what they need- ✅ The tools that send the browser extension to the stores, at their current versions+- ✅ macOS: downloads to a network volume (SMB, AFP, NFS), refused for "0 bytes free"+ ([#623](https://github.com/anefzaoui/misterdownloadmanager/issues/623))## Being worked ondiff --git a/crates/engine/src/disk.rs b/crates/engine/src/disk.rsindex b465b65c..5d42777a 100644--- a/crates/engine/src/disk.rs+++ b/crates/engine/src/disk.rs@@ -19,10 +19,11 @@ pub struct Volume {/// The bytes a new file may take, as each system counts them for the user: on Windows the/// space this user may use, disk quotas included (GetDiskFreeSpaceExW); on Linux and other/// Unix systems the blocks left to programs that aren't root (statvfs's `f_bavail`); on- /// macOS the volume's capacity "for important usage", which includes the purgeable space+ /// macOS a local volume's capacity "for important usage", which includes the purgeable space/// (caches, local snapshots) the system frees as soon as a program writes. Finder shows the/// same number; statvfs leaves the purgeable space out, and would refuse a download that- /// fits.+ /// fits. A network volume on macOS has no purgeable space and answers that capacity with 0:+ /// its statvfs count is used (#623, `free_on_apple`).pub free: u64,/// As the system names it (`NTFS`, `FAT32`, `exFAT`; `ext4`, `vfat`; `apfs`, `msdos`), or/// empty when it can't tell: the space is still checked.@@ -168,7 +169,7 @@ mod imp {// The blocks a program may use (without the reserve kept for root).let free = st.f_bavail.saturating_mul(block);#[cfg(target_vendor = "apple")]- let free = apple::important_capacity(dir).unwrap_or(free);+ let free = super::free_on_apple(free, apple::important_capacity(dir), apple::is_local(dir));Some(super::Volume {free,file_system: file_system(dir),@@ -232,6 +233,14 @@ mod imp {let bytes = value.downcast::<CFNumber>()?.to_i64()?;u64::try_from(bytes).ok()}++ /// Whether the folder's volume is on this computer (`MNT_LOCAL` in statfs's flags), not a+ /// network share (SMB, AFP, NFS, WebDAV). False when the system can't tell.+ pub fn is_local(dir: &Path) -> bool {+ /// `<sys/mount.h>`: "filesystem is stored locally".+ const MNT_LOCAL: u32 = 0x0000_1000;+ rustix::fs::statfs(dir).is_ok_and(|st| st.f_flags & MNT_LOCAL != 0)+ }}/// Linux tells a file system by a number; the FAT check needs `vfat`'s, the others are@@ -284,6 +293,22 @@ mod imp {}}+/// The free space a new file may take on Apple's systems, from statvfs's count (`statvfs`), the+/// volume's capacity "for important usage" (`important`, None when it can't tell) and whether the+/// volume is on this computer (`local`).+///+/// The important-usage capacity adds the purgeable space the system frees on demand, a local+/// volume's notion (APFS caches and snapshots). A network volume (SMB, AFP, NFS) answers it with+/// 0, and taking that 0 refused every download to it (#623): there, and whenever it answers 0,+/// statvfs's count is the free space. Portable, so its tests run on every system.+#[cfg(any(target_vendor = "apple", test))]+fn free_on_apple(statvfs: u64, important: Option<u64>, local: bool) -> u64 {+ match important {+ Some(bytes) if local && bytes > 0 => bytes,+ _ => statvfs,+ }+}+/// Neither Windows nor Unix: no probe, the check is skipped.#[cfg(not(any(windows, unix)))]mod imp {@@ -378,6 +403,33 @@ mod tests {assert!(check(&vol(1 << 30, ""), 8 << 30).is_err());}+ #[test]+ fn a_network_volume_on_apple_counts_statvfs() {+ const TB: u64 = 1 << 40;+ // #623: a share with terabytes free answers 0 for important usage. The probe took that+ // 0, and a 3.28 KB download was refused with "0 bytes free".+ let free = free_on_apple(4 * TB, Some(0), false);+ assert_eq!(free, 4 * TB);+ assert!(check(&vol(free, "smbfs"), 3360).is_ok());+ assert!(matches!(+ check(&vol(0, "smbfs"), 3360),+ Err(Refusal::NoSpace { free: 0, .. })+ ));+ // A share's answer isn't taken even when it isn't 0 (it has no purgeable space).+ for fs_answer in [Some(1), Some(TB), None] {+ assert_eq!(+ free_on_apple(4 * TB, fs_answer, false),+ 4 * TB,+ "{fs_answer:?}"+ );+ }+ // A local volume: the important-usage capacity, purgeable space included (#224), unless+ // it says 0 or nothing.+ assert_eq!(free_on_apple(10 << 30, Some(12 << 30), true), 12 << 30);+ assert_eq!(free_on_apple(10 << 30, Some(0), true), 10 << 30);+ assert_eq!(free_on_apple(10 << 30, None, true), 10 << 30);+ }+#[test]fn sizes_read_like_idms() {assert_eq!(human(512), "512 bytes");