Skip to content

Commit 4a5d21e

Browse files
committed
upload: Show upload size properly in log
Implement size calculation for streaming upload. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
1 parent ff67772 commit 4a5d21e

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

src/azure.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async fn write_file_to_blob_streaming(
8383
data: &mut (dyn tokio::io::AsyncRead + Unpin + Send),
8484
cont_type: String,
8585
owner_email: Option<String>,
86-
) -> &'static str {
86+
) -> (&'static str, usize) {
8787
let azure_cfg = Arc::new(get_azure_credentials("azure"));
8888

8989
let storage_account = azure_cfg.account.as_str();
@@ -177,7 +177,7 @@ async fn write_file_to_blob_streaming(
177177
eprintln!("Error uploading block list: {:?}", e);
178178
}
179179
}
180-
"OK"
180+
("OK", total_bytes_uploaded)
181181
}
182182

183183
/// Write file to Azure blob storage (legacy version using Vec<u8>)
@@ -557,9 +557,9 @@ impl super::Driver for AzureDriver {
557557
data: &mut (dyn tokio::io::AsyncRead + Unpin + Send),
558558
cont_type: String,
559559
owner_email: Option<String>,
560-
) -> String {
561-
write_file_to_blob_streaming(filename.clone(), data, cont_type, owner_email).await;
562-
filename
560+
) -> (String, usize) {
561+
let (_status, size) = write_file_to_blob_streaming(filename.clone(), data, cont_type, owner_email).await;
562+
(filename, size)
563563
}
564564
fn tag_file(
565565
&self,

src/local.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async fn write_file_to_local_streaming(
9999
data: &mut (dyn tokio::io::AsyncRead + Unpin + Send),
100100
cont_type: String,
101101
owner_email: Option<String>,
102-
) -> Result<String, String> {
102+
) -> Result<(String, usize), String> {
103103
let file_path = get_storage_file_path(&filename);
104104

105105
// Ensure directory structure exists
@@ -140,7 +140,7 @@ async fn write_file_to_local_streaming(
140140
}
141141

142142
debug_log!("File written to local storage: {}", file_path.display());
143-
Ok(filename)
143+
Ok((filename, total_bytes))
144144
}
145145

146146
/// Write file to local storage (legacy version using Vec<u8>)
@@ -348,12 +348,12 @@ impl super::Driver for LocalDriver {
348348
data: &mut (dyn tokio::io::AsyncRead + Unpin + Send),
349349
cont_type: String,
350350
owner_email: Option<String>,
351-
) -> String {
351+
) -> (String, usize) {
352352
match write_file_to_local_streaming(filename.clone(), data, cont_type, owner_email).await {
353-
Ok(_) => filename,
353+
Ok((fname, size)) => (fname, size),
354354
Err(e) => {
355355
eprintln!("Local storage streaming write error: {}", e);
356-
String::new()
356+
(String::new(), 0)
357357
}
358358
}
359359
}

src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ trait Driver: Send + Sync {
194194
data: &mut (dyn tokio::io::AsyncRead + Unpin + Send),
195195
cont_type: String,
196196
owner_email: Option<String>,
197-
) -> String;
197+
) -> (String, usize);
198198
fn get_file(&self, filename: String) -> ReceivedFile;
199199
fn tag_file(
200200
&self,
@@ -630,7 +630,7 @@ async fn ax_post_file(
630630
let driver_name = get_driver_type();
631631
let driver = init_driver(&driver_name);
632632

633-
let result = driver.write_file_streaming(
633+
let (result, file_size) = driver.write_file_streaming(
634634
full_path.clone(),
635635
&mut field_stream,
636636
content_type.to_string(),
@@ -651,7 +651,7 @@ async fn ax_post_file(
651651
"{} {} {} {} {} {} {} {}",
652652
client_ip,
653653
status.as_u16(),
654-
"streaming",
654+
file_size,
655655
human_time,
656656
Method::POST,
657657
request_target,

0 commit comments

Comments
 (0)