From 25422ed089cd0f3b4186cfb24d27114efcf88f70 Mon Sep 17 00:00:00 2001 From: PatrykHegenberg <112555272+PatrykHegenberg@users.noreply.github.com> Date: Fri, 17 May 2024 10:25:48 +0200 Subject: [PATCH] fix(receiver): add filepath for download on android. --- caesar-core/src/receiver/client.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/caesar-core/src/receiver/client.rs b/caesar-core/src/receiver/client.rs index ae632eb..bcb2c2d 100644 --- a/caesar-core/src/receiver/client.rs +++ b/caesar-core/src/receiver/client.rs @@ -22,6 +22,9 @@ use tracing::error; const DESTINATION: u8 = 0; const NONCE_SIZE: usize = 12; +#[cfg(target_os = "android")] +const FILE_PATH_PREFIX: &str = "/storage/emulated/0/Download"; + struct File { name: String, size: u64, @@ -73,11 +76,29 @@ fn on_list(context: &mut Context, list: ListPacket) -> Status { for entry in list.entries { let path = sanitize_filename::sanitize(entry.name.clone()); + #[cfg(target_os = "android")] + let file_path = format!("{}/{}", FILE_PATH_PREFIX, path); + #[cfg(target_os = "android")] + if Path::new(&file_path).exists() { + return Status::Err(format!("The file '{}' already exists.", path)); + } + #[cfg(target_os = "android")] + let handle = match fs::File::create(&file_path) { + Ok(handle) => handle, + Err(error) => { + return Status::Err(format!( + "Error: Failed to create file '{}': {}", + file_path, error + )); + } + }; + #[cfg(not(target_os = "android"))] if Path::new(&path).exists() { return Status::Err(format!("The file '{}' already exists.", path)); } - + + #[cfg(not(target_os = "android"))] let handle = match fs::File::create(&path) { Ok(handle) => handle, Err(error) => {