An open-source cross-platform alternative to AirDrop
feat: log file content read
Tien Do Namd3467753ff23
diff --git a/app/rust/Cargo.lock b/app/rust/Cargo.lockindex 677918dd..e34f716c 100644--- a/app/rust/Cargo.lock+++ b/app/rust/Cargo.lock@@ -79,6 +79,12 @@ version = "0.2.21"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"+[[package]]+name = "android_log-sys"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "85965b6739a430150bdd138e2374a98af0c3ee0d030b3bb7fc3bddff58d0102e"+[[package]]name = "android_log-sys"version = "0.3.2"@@ -91,7 +97,7 @@ version = "0.15.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "dbb4e440d04be07da1f1bf44fb4495ebd58669372fe0cffa6e48595ac5bd88a3"dependencies = [- "android_log-sys",+ "android_log-sys 0.3.2","env_filter","log",]@@ -2153,6 +2159,7 @@ dependencies = ["tokio","tokio-util","tracing",+ "tracing-android","tracing-subscriber","uuid",]@@ -2826,6 +2833,17 @@ dependencies = ["tracing-core",]+[[package]]+name = "tracing-android"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "12612be8f868a09c0ceae7113ff26afe79d81a24473a393cb9120ece162e86c0"+dependencies = [+ "android_log-sys 0.2.0",+ "tracing",+ "tracing-subscriber",+]+[[package]]name = "tracing-attributes"version = "0.1.31"diff --git a/app/rust/Cargo.toml b/app/rust/Cargo.tomlindex bcca54ea..a2b00d68 100644--- a/app/rust/Cargo.toml+++ b/app/rust/Cargo.toml@@ -16,3 +16,6 @@ tokio-util = "0.7.16"tracing = "0.1.44"tracing-subscriber = { version = "0.3.22" }uuid = { version = "1.11.1", features = ["v4"] }++[target.'cfg(target_os = "android")'.dependencies]+tracing-android = "0.2"diff --git a/app/rust/src/api/logging.rs b/app/rust/src/api/logging.rsindex 124507fb..392129b3 100644--- a/app/rust/src/api/logging.rs+++ b/app/rust/src/api/logging.rs@@ -1,9 +1,22 @@use anyhow::Result;-use tracing::Level;pub fn enable_debug_logging() -> Result<()> {+ #[cfg(target_os = "android")]+ {+ use tracing_subscriber::layer::SubscriberExt;+ use tracing_subscriber::util::SubscriberInitExt;++ // Android discards native stdout/stderr, so route tracing to logcat.+ tracing_subscriber::registry()+ .with(tracing_subscriber::filter::LevelFilter::DEBUG)+ .with(tracing_android::layer("localsend_rust")?)+ .try_init()+ .map_err(|e| anyhow::anyhow!(e.to_string()))?;+ }++ #[cfg(not(target_os = "android"))]tracing_subscriber::fmt()- .with_max_level(Level::DEBUG)+ .with_max_level(tracing::Level::DEBUG).try_init().map_err(|e| anyhow::anyhow!(e.to_string()))?;diff --git a/packages/core/src/model/transfer.rs b/packages/core/src/model/transfer.rsindex b3f1be20..425c1070 100644--- a/packages/core/src/model/transfer.rs+++ b/packages/core/src/model/transfer.rs@@ -33,8 +33,12 @@ impl FileContent {/// chunks; the channel is closed on EOF or on an I/O error.pub fn into_receiver(self) -> mpsc::Receiver<Bytes> {match self {- FileContent::Stream(rx) => rx,+ FileContent::Stream(rx) => {+ tracing::info!("Reading file content via byte stream from application");+ rx+ },FileContent::Path(path) => {+ tracing::info!("Reading file content from path: {}", path.display());let (tx, rx) = mpsc::channel(FILE_CHANNEL_CAPACITY);tokio::spawn(async move {match tokio::fs::File::open(&path).await {@@ -50,6 +54,7 @@ impl FileContent {FileContent::Fd(fd) => {use std::os::fd::FromRawFd;+ tracing::info!("Reading file content from file descriptor: {fd}");let (tx, rx) = mpsc::channel(FILE_CHANNEL_CAPACITY);// SAFETY: the descriptor is owned by this transfer; wrapping it in// a File transfers that ownership so it is closed once reading finishes.@@ -69,10 +74,12 @@ async fn read_file_into_sender(mut file: tokio::fs::File, tx: mpsc::Sender<Bytesuse tokio::io::AsyncReadExt;let mut buffer = bytes::BytesMut::with_capacity(64 * 1024);+ let mut total: u64 = 0;loop {match file.read_buf(&mut buffer).await {Ok(0) => break,- Ok(_) => {+ Ok(n) => {+ total += n as u64;if tx.send(buffer.split().freeze()).await.is_err() {break;}@@ -83,6 +90,7 @@ async fn read_file_into_sender(mut file: tokio::fs::File, tx: mpsc::Sender<Bytes}}}+ tracing::info!("Finished reading file content ({total} bytes)");}#[derive(Debug, Clone, Serialize, Deserialize)]