Skip to content

Commit 2f4a159

Browse files
committed
Ensure we are printing to the correct output stream for all download sources
1 parent 19c24b8 commit 2f4a159

4 files changed

Lines changed: 26 additions & 25 deletions

File tree

src/download_sources/apkpure.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ pub async fn download_apps(
4949
async move {
5050
let app_string = match app_version {
5151
Some(ref version) => {
52-
mp_log.println(format!("Downloading {} version {}...", app_id, version)).unwrap();
52+
mp_log.suspend(|| println!("Downloading {} version {}...", app_id, version));
5353
format!("{}@{}", app_id, version)
5454
},
5555
None => {
56-
mp_log.println(format!("Downloading {}...", app_id)).unwrap();
56+
mp_log.suspend(|| println!("Downloading {}...", app_id));
5757
app_id.to_string()
5858
},
5959
};
@@ -101,7 +101,7 @@ async fn download_from_response(response: Response, re: Box<dyn Deref<Target=Reg
101101
};
102102

103103
match dl.download(&cb).await {
104-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap(),
104+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_string)),
105105
Err(err) if matches!(err.kind(), TDSTDErrorKind::FileExists) => {
106106
mp_log.println(format!("File already exists for {}. Skipping...", app_string)).unwrap();
107107
},
@@ -111,11 +111,11 @@ async fn download_from_response(response: Response, re: Box<dyn Deref<Target=Reg
111111
Err(_) => {
112112
mp_log.println(format!("An error has occurred attempting to download {}. Retry #1...", app_string)).unwrap();
113113
match AsyncDownload::new(download_url, Path::new(outpath), &fname).download(&cb).await {
114-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap(),
114+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_string)),
115115
Err(_) => {
116116
mp_log.println(format!("An error has occurred attempting to download {}. Retry #2...", app_string)).unwrap();
117117
match AsyncDownload::new(download_url, Path::new(outpath), &fname).download(&cb).await {
118-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap(),
118+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_string)),
119119
Err(_) => {
120120
mp_log.println(format!("An error has occurred attempting to download {}. Skipping...", app_string)).unwrap();
121121
}

src/download_sources/fdroid.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,19 @@ pub async fn download_apps(
216216
async move {
217217
let app_string = match (app_version, app_arch) {
218218
(None, None) => {
219-
mp_log.println(format!("Downloading {}...", app_id)).unwrap();
219+
mp_log.suspend(|| println!("Downloading {}...", app_id));
220220
app_id.to_string()
221221
},
222222
(None, Some(arch)) => {
223-
mp_log.println(format!("Downloading {} arch {}...", app_id, arch)).unwrap();
223+
mp_log.suspend(|| println!("Downloading {} arch {}...", app_id, arch));
224224
format!("{}@{}", app_id, arch)
225225
},
226226
(Some(version), None) => {
227-
mp_log.println(format!("Downloading {} version {}...", app_id, version)).unwrap();
227+
mp_log.suspend(|| println!("Downloading {} version {}...", app_id, version));
228228
format!("{}@{}", app_id, version)
229229
},
230230
(Some(version), Some(arch)) => {
231-
mp_log.println(format!("Downloading {} version {} arch {}...", app_id, version, arch)).unwrap();
231+
mp_log.suspend(|| println!("Downloading {} version {} arch {}...", app_id, version, arch));
232232
format!("{}@{}@{}", app_id, version, arch)
233233
},
234234
};
@@ -274,9 +274,9 @@ pub async fn download_apps(
274274
};
275275
if let Some(sha256sum) = sha256sum {
276276
if sha256sum == hash {
277-
mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap();
277+
mp_log.suspend(|| println!("{} downloaded successfully!", app_string));
278278
} else {
279-
mp_log.println(format!("{} downloaded, but the sha256sum does not match the one signed by F-Droid. Proceed with caution.", app_string)).unwrap();
279+
mp_log.suspend(|| println!("{} downloaded, but the sha256sum does not match the one signed by F-Droid. Proceed with caution.", app_string));
280280
}
281281
}
282282
},
@@ -396,7 +396,8 @@ pub async fn list_versions(apps: Vec<(String, Option<String>)>, options: HashMap
396396
let index = retrieve_index_or_exit(&options, mp, output_format.clone()).await;
397397

398398
if parse_json_display_versions(index, apps, output_format).is_err() {
399-
println!("Could not parse JSON of F-Droid package index. Exiting.");
399+
eprintln!("Could not parse JSON of F-Droid package index. Exiting.");
400+
std::process::exit(1);
400401
};
401402
}
402403

@@ -671,7 +672,7 @@ fn get_signed_data_from_cert_file(signature_block_file: PathBuf) -> Result<Signe
671672

672673
async fn download_and_extract_to_tempdir(dir: &TempDir, repo: &str, mp: Rc<MultiProgress>, use_entry: bool, output_format: OutputFormat) -> Vec<String> {
673674
let mp_log = Rc::clone(&mp);
674-
mp_log.println(format!("Downloading F-Droid package repository...")).unwrap();
675+
mp_log.suspend(|| println!("Downloading F-Droid package repository..."));
675676
let mut files = vec![];
676677
let fdroid_jar_url = if use_entry {
677678
format!("{}/entry.jar", repo)
@@ -687,7 +688,7 @@ async fn download_and_extract_to_tempdir(dir: &TempDir, repo: &str, mp: Rc<Multi
687688
};
688689
match dl.download(&cb).await {
689690
Ok(_) => {
690-
mp_log.println(format!("Package repository downloaded successfully!\nExtracting...")).unwrap();
691+
mp_log.suspend(|| println!("Package repository downloaded successfully!\nExtracting..."));
691692
let file = fs::File::open(dir.path().join(jar_local_file)).unwrap();
692693
match zip::ZipArchive::new(file) {
693694
Ok(mut archive) => {

src/download_sources/google_play.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ pub async fn download_apps(
4646
match gpa.accept_tos().await {
4747
Ok(_) => {
4848
if let Err(_) = gpa.login().await {
49-
println!("Could not log in, even after accepting the Google Play Terms of Service");
49+
eprintln!("Could not log in, even after accepting the Google Play Terms of Service");
5050
std::process::exit(1);
5151
}
5252
println!("Google Play Terms of Service accepted.");
5353
},
5454
_ => {
55-
println!("Could not accept Google Play Terms of Service");
55+
eprintln!("Could not accept Google Play Terms of Service");
5656
std::process::exit(1);
5757
},
5858
}
@@ -62,7 +62,7 @@ pub async fn download_apps(
6262
}
6363
},
6464
_ => {
65-
println!("Could not log in to Google Play. Please check your credentials and try again later. {}", err);
65+
eprintln!("Could not log in to Google Play. Please check your credentials and try again later. {}", err);
6666
std::process::exit(1);
6767
}
6868
}
@@ -81,12 +81,12 @@ pub async fn download_apps(
8181

8282
async move {
8383
if app_version.is_none() {
84-
mp_log.println(format!("Downloading {}...", app_id)).unwrap();
84+
mp_log.suspend(|| println!("Downloading {}...", app_id));
8585
if sleep_duration > 0 {
8686
sleep(TokioDuration::from_millis(sleep_duration)).await;
8787
}
8888
match gpa.download(&app_id, None, split_apk, include_additional_files, Path::new(outpath), Some(&progress_wrapper(mp_dl1))).await {
89-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_id)).unwrap(),
89+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_id)),
9090
Err(err) if matches!(err.kind(), GpapiErrorKind::FileExists) => {
9191
mp_log.println(format!("File already exists for {}. Skipping...", app_id)).unwrap();
9292
}
@@ -102,11 +102,11 @@ pub async fn download_apps(
102102
Err(_) => {
103103
mp_log.println(format!("An error has occurred attempting to download {}. Retry #1...", app_id)).unwrap();
104104
match gpa.download(&app_id, None, split_apk, include_additional_files, Path::new(outpath), Some(&progress_wrapper(mp_dl2))).await {
105-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_id)).unwrap(),
105+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_id)),
106106
Err(_) => {
107107
mp_log.println(format!("An error has occurred attempting to download {}. Retry #2...", app_id)).unwrap();
108108
match gpa.download(&app_id, None, split_apk, include_additional_files, Path::new(outpath), Some(&progress_wrapper(mp_dl3))).await {
109-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_id)).unwrap(),
109+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_id)),
110110
Err(_) => {
111111
mp_log.println(format!("An error has occurred attempting to download {}. Skipping...", app_id)).unwrap();
112112
}

src/download_sources/huawei_app_gallery.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub async fn download_apps(
4040
let mp_log = Rc::clone(&mp);
4141
async move {
4242
if app_version.is_none() {
43-
mp_log.println(format!("Downloading {}...", app_id)).unwrap();
43+
mp_log.suspend(|| println!("Downloading {}...", app_id));
4444
if sleep_duration > 0 {
4545
sleep(TokioDuration::from_millis(sleep_duration)).await;
4646
}
@@ -88,7 +88,7 @@ async fn download_from_response(response: Response, app_string: String, outpath:
8888
};
8989

9090
match dl.download(&cb).await {
91-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap(),
91+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_string)),
9292
Err(err) if matches!(err.kind(), TDSTDErrorKind::FileExists) => {
9393
mp_log.println(format!("File already exists for {}. Skipping...", app_string)).unwrap();
9494
},
@@ -98,11 +98,11 @@ async fn download_from_response(response: Response, app_string: String, outpath:
9898
Err(_) => {
9999
mp_log.println(format!("An error has occurred attempting to download {}. Retry #1...", app_string)).unwrap();
100100
match AsyncDownload::new(download_url, Path::new(outpath), &fname).download(&cb).await {
101-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap(),
101+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_string)),
102102
Err(_) => {
103103
mp_log.println(format!("An error has occurred attempting to download {}. Retry #2...", app_string)).unwrap();
104104
match AsyncDownload::new(download_url, Path::new(outpath), &fname).download(&cb).await {
105-
Ok(_) => mp_log.println(format!("{} downloaded successfully!", app_string)).unwrap(),
105+
Ok(_) => mp_log.suspend(|| println!("{} downloaded successfully!", app_string)),
106106
Err(_) => {
107107
mp_log.println(format!("An error has occurred attempting to download {}. Skipping...", app_string)).unwrap();
108108
}

0 commit comments

Comments
 (0)