about summary refs log tree commit diff stats
path: root/sys/nixpkgs/pkgs/yt/src/downloader.rs
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-01-21 14:33:38 +0100
committerSoispha <soispha@vhack.eu>2024-01-21 14:33:38 +0100
commit1ccb1246641265f384e51f7a72f0589a1dd28fad (patch)
treee064b818b9a3e1173cf24a4f7dba05da4530cdea /sys/nixpkgs/pkgs/yt/src/downloader.rs
parentfeat(sys/nixpkgs/yt): Add support for the 'url' command (diff)
downloadnixos-config-1ccb1246641265f384e51f7a72f0589a1dd28fad.tar.gz
nixos-config-1ccb1246641265f384e51f7a72f0589a1dd28fad.zip
fix(sys/nixpkgs/yt): Ensure that the downloader downloads everything
Diffstat (limited to 'sys/nixpkgs/pkgs/yt/src/downloader.rs')
-rw-r--r--sys/nixpkgs/pkgs/yt/src/downloader.rs12
1 files changed, 7 insertions, 5 deletions
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),
         }
     }