Skip to content

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

Engine: a download finishing during a progress save no longer fails (#116) (#120)

Ahmed Nefzaoui01ad2d2a902a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f15f5263..2d9aea91 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -228,6 +228,10 @@ Each release's notes on GitHub come from its section here (`## [X.Y.Z]`, see
download's progress every few seconds, in a file beside it. A download paused or finished
during one of those saves could stop before the save was done. That save then wrote an old
progress file a moment later. A download now stops only once its save is done.
+- **A download could fail as it finished, with "part file still in use"**
+ ([#116](https://github.com/anefzaoui/misterdownloadmanager/issues/116)). It happened when the
+ last bytes arrived during a progress save, which still held the file. It has the same cause
+ and fix as the one above.
- **A video download could fail in MDM while yt-dlp went on and finished it**
([#79](https://github.com/anefzaoui/misterdownloadmanager/issues/79)). A line yt-dlp printed in
the system's code page rather than UTF-8 (a title in Turkish or Russian on some Windows) ended
diff --git a/ROADMAP.md b/ROADMAP.md
index 781afb09..de18986a 100644
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@ -14,7 +14,8 @@ Everything below ships together, in one release.
### Done
- ✅ A paused or finished download no longer leaves its progress file to be written again a moment
- later ([#106](https://github.com/anefzaoui/misterdownloadmanager/issues/106))
+ later ([#106](https://github.com/anefzaoui/misterdownloadmanager/issues/106)), and a download
+ finishing during a save no longer fails ([#116](https://github.com/anefzaoui/misterdownloadmanager/issues/116))
- ✅ Tests and test tools stay on 127.0.0.1: no Windows Firewall questions while developing
- ✅ Downloads through one network adapter (a VPN's), with a kill switch: nothing goes out
another way when it disconnects ([#35](https://github.com/anefzaoui/misterdownloadmanager/issues/35))
diff --git a/crates/engine/tests/e2e.rs b/crates/engine/tests/e2e.rs
index f423c29c..4ecc893f 100644
--- a/crates/engine/tests/e2e.rs
+++ b/crates/engine/tests/e2e.rs
@@ -930,6 +930,31 @@ async fn cookies_are_sent_to_their_own_host() {
);
}
+#[tokio::test]
+async fn a_download_completing_during_a_progress_save_finishes() {
+ // #116: progress saved every millisecond, so one is under way (flushing the part file) as
+ // the last bytes arrive. The download must wait for it, then finish: no "part file still
+ // in use", and no progress file written beside the finished file afterwards (#106).
+ let s = server("rate=4M").await;
+ let dir = tempfile::tempdir().unwrap();
+ let req = Request {
+ url: s.url("/gen/8M/s.bin?seed=34").parse().unwrap(),
+ headers: Default::default(),
+ dest: Destination::Dir(dir.path().to_owned()),
+ };
+ let opts = Options {
+ save_interval: std::time::Duration::from_millis(1),
+ ..fast_opts()
+ };
+ let out = Download::start(req, opts).wait().await.expect("finished");
+ assert_eq!(std::fs::metadata(&out.path).unwrap().len(), 8 << 20);
+ tokio::time::sleep(std::time::Duration::from_millis(500)).await;
+ assert!(
+ !mdm_engine::state::state_path(&out.path).exists(),
+ "no progress file beside the finished file"
+ );
+}
+
#[tokio::test]
async fn crash_after_the_final_rename_completes_on_resume() {
let s = server("rate=1M").await;