Skip to content

Commit

Permalink
fix: each Ctrl-C only cancel 10 jobs(a batch);
Browse files Browse the repository at this point in the history
  • Loading branch information
kingwingfly committed Feb 6, 2024
1 parent f8b0c6c commit 56f7f35
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pub enum ApiError {
LogoutFail { source: reqwest::Error, msg: String },
#[snafu(display("{}", msg))]
PullFail { msg: String },
#[snafu(display("Ctrl-C Cancelled"))]
Canclled,
#[snafu(display("Create temp file fail"), context(false))]
CreateTempFileFail { source: std::io::Error },
#[snafu(display("Persist temp file fail"), context(false))]
Expand Down
10 changes: 6 additions & 4 deletions src/api/pull.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::error::MergeFail;
use super::wbi::{encode_wbi, get_wbi_keys};
use super::{client, error::Result, parse_message};
use crate::api::error::PullFail;
use crate::api::error::{ApiError, Canclled, PullFail};
use crate::cli::utils::download_bar;
use crate::config::config;
use crate::proto::data::{Dash, Meta, Qn, VideoMeta};
Expand Down Expand Up @@ -62,6 +62,10 @@ async fn try_pull(videos: Vec<*mut VideoMeta>) {
(**v).saved = true;
}
}
Err(ApiError::Canclled) => {
warn!("Pulling is canclled");
return;
}
Err(e) => warn!("{}", e),
}
}
Expand Down Expand Up @@ -147,9 +151,7 @@ async fn download(title: &str, v_url: &str, a_url: &str) -> Result<()> {
_ = tokio::signal::ctrl_c() => {
file_v.into_inner().unwrap().close()?;
file_a.into_inner().unwrap().close()?;
return PullFail {
msg: "Download Cancelled; Ctrl-C",
}.fail();
return Canclled.fail();
}

}
Expand Down

0 comments on commit 56f7f35

Please sign in to comment.