fix: sending file from local to remote (keep send_raw)

This commit is contained in:
csf 2022-11-16 18:53:32 +09:00
parent c6082e0a25
commit 50dc2a4d73
4 changed files with 26 additions and 26 deletions

View File

@ -380,7 +380,7 @@ impl TransferJob {
}
}
pub async fn write(&mut self, block: FileTransferBlock, raw: Option<&[u8]>) -> ResultType<()> {
pub async fn write(&mut self, block: FileTransferBlock) -> ResultType<()> {
if block.id != self.id {
bail!("Wrong id");
}
@ -402,20 +402,15 @@ impl TransferJob {
let path = format!("{}.download", get_string(&path));
self.file = Some(File::create(&path).await?);
}
let data = if let Some(data) = raw {
data
} else {
&block.data
};
if block.compressed {
let tmp = decompress(data);
let tmp = decompress(&block.data);
self.file.as_mut().unwrap().write_all(&tmp).await?;
self.finished_size += tmp.len() as u64;
} else {
self.file.as_mut().unwrap().write_all(data).await?;
self.finished_size += data.len() as u64;
self.file.as_mut().unwrap().write_all(&block.data).await?;
self.finished_size += block.data.len() as u64;
}
self.transferred += data.len() as u64;
self.transferred += block.data.len() as u64;
Ok(())
}

View File

@ -925,7 +925,7 @@ impl<T: InvokeUiSession> Remote<T> {
block.file_num
);
if let Some(job) = fs::get_job(block.id, &mut self.write_jobs) {
if let Err(_err) = job.write(block, None).await {
if let Err(_err) = job.write(block).await {
// to-do: add "skip" for writing job
}
self.update_jobs_status();

View File

@ -1609,7 +1609,8 @@ async fn start_ipc(
file_num,
data,
compressed}) = data {
stream.send(&Data::FS(ipc::FS::WriteBlock{id, file_num, data, compressed})).await?;
stream.send(&Data::FS(ipc::FS::WriteBlock{id, file_num, data: Bytes::new(), compressed})).await?;
stream.send_raw(data).await?;
} else {
stream.send(&data).await?;
}

View File

@ -1,3 +1,5 @@
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
use std::iter::FromIterator;
#[cfg(windows)]
use std::sync::Arc;
use std::{
@ -8,8 +10,6 @@ use std::{
RwLock,
},
};
#[cfg(any(target_os = "android", target_os = "ios", feature = "flutter"))]
use std::iter::FromIterator;
#[cfg(windows)]
use clipboard::{cliprdr::CliprdrClientContext, empty_clipboard, set_conn_enabled, ContextSend};
@ -337,8 +337,15 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
Data::ChatMessage { text } => {
self.cm.new_message(self.conn_id, text);
}
Data::FS(fs) => {
handle_fs(fs, &mut write_jobs, &self.tx).await;
Data::FS(mut fs) => {
if let ipc::FS::WriteBlock { id, file_num, data: _, compressed } = fs {
if let Ok(bytes) = self.stream.next_raw().await {
fs = ipc::FS::WriteBlock{id, file_num, data:bytes.into(), compressed};
handle_fs(fs, &mut write_jobs, &self.tx).await;
}
} else {
handle_fs(fs, &mut write_jobs, &self.tx).await;
}
}
#[cfg(windows)]
Data::ClipbaordFile(_clip) => {
@ -588,16 +595,13 @@ async fn handle_fs(fs: ipc::FS, write_jobs: &mut Vec<fs::TransferJob>, tx: &Unbo
} => {
if let Some(job) = fs::get_job(id, write_jobs) {
if let Err(err) = job
.write(
FileTransferBlock {
id,
file_num,
data,
compressed,
..Default::default()
},
None,
)
.write(FileTransferBlock {
id,
file_num,
data,
compressed,
..Default::default()
})
.await
{
send_raw(fs::new_error(id, err, file_num), &tx);