From 1ccb1246641265f384e51f7a72f0589a1dd28fad Mon Sep 17 00:00:00 2001 From: Soispha Date: Sun, 21 Jan 2024 14:33:38 +0100 Subject: fix(sys/nixpkgs/yt): Ensure that the downloader downloads everything --- sys/nixpkgs/pkgs/yt/src/downloader.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'sys/nixpkgs/pkgs/yt/src/downloader.rs') diff --git a/sys/nixpkgs/pkgs/yt/src/downloader.rs b/sys/nixpkgs/pkgs/yt/src/downloader.rs index b30c49a2..f29f4a3b 100644 --- a/sys/nixpkgs/pkgs/yt/src/downloader.rs +++ b/sys/nixpkgs/pkgs/yt/src/downloader.rs @@ -74,8 +74,9 @@ impl Downloader { pub fn add(&mut self, number_to_add: u32) -> Result<()> { debug!("Adding {} to be downloaded concurrently", number_to_add); for _ in 0..number_to_add { - let pt = self.playspec.pop().context("No more playthings to pop")?; + let pt = self.playspec.pop().expect("This call should be guarded"); self.itx.as_ref().expect("Should still be valid").send(pt)?; + self.sent += 1; } Ok(()) } @@ -86,9 +87,7 @@ impl Downloader { match self.orx.recv() { Ok(ok) => { debug!("Output downloaded to: {}", ok.0.display()); - self.sent += 1; - if self.sent < self.playspec.len() { - debug!("Will add 1"); + if !self.playspec.is_empty() { self.add(1).ok()?; } else { debug!( @@ -107,10 +106,13 @@ impl Downloader { } } } + pub fn drop(self) -> anyhow::Result<()> { + // Check that we really downloaded everything + assert_eq!(self.playspec.len(), 0); match self.download_thread.join() { Ok(ok) => ok, - Err(err) => panic!("Can't join thread: '{:#?}'", err), + Err(err) => panic!("Failed to join downloader thread: '{:#?}'", err), } } -- cgit 1.4.1