add: server override
This commit is contained in:
parent
8854fcbe85
commit
51caeafebd
@ -506,7 +506,7 @@ impl TransferJob {
|
|||||||
match r.union {
|
match r.union {
|
||||||
Some(file_transfer_send_confirm_request::Union::skip(s)) => {
|
Some(file_transfer_send_confirm_request::Union::skip(s)) => {
|
||||||
if s {
|
if s {
|
||||||
log::debug!("skip current file");
|
println!("skip current file");
|
||||||
self.skip_current_file();
|
self.skip_current_file();
|
||||||
} else {
|
} else {
|
||||||
self.set_file_confirmed(true);
|
self.set_file_confirmed(true);
|
||||||
@ -561,6 +561,15 @@ pub fn new_block(block: FileTransferBlock) -> Message {
|
|||||||
msg_out
|
msg_out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn new_send_confirm(r: FileTransferSendConfirmRequest) -> Message {
|
||||||
|
let mut msg_out = Message::new();
|
||||||
|
let mut action = FileAction::new();
|
||||||
|
action.set_send_confirm(r);
|
||||||
|
msg_out.set_file_action(action);
|
||||||
|
msg_out
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_receive(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
pub fn new_receive(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
||||||
let mut action = FileAction::new();
|
let mut action = FileAction::new();
|
||||||
@ -678,14 +687,14 @@ pub fn create_dir(dir: &str) -> ResultType<()> {
|
|||||||
pub fn is_write_need_confirmation(
|
pub fn is_write_need_confirmation(
|
||||||
file_path: &str,
|
file_path: &str,
|
||||||
digest: &FileTransferDigest,
|
digest: &FileTransferDigest,
|
||||||
) -> ResultType<bool> {
|
) -> ResultType<Option<FileTransferDigest>> {
|
||||||
let path = Path::new(file_path);
|
let path = Path::new(file_path);
|
||||||
if path.exists() && path.is_file() {
|
if path.exists() && path.is_file() {
|
||||||
let metadata = std::fs::metadata(path)?;
|
let metadata = std::fs::metadata(path)?;
|
||||||
let modified_time = metadata.modified()?;
|
let modified_time = metadata.modified()?;
|
||||||
let remote_mt = Duration::from_secs(digest.last_edit_timestamp);
|
let remote_mt = Duration::from_secs(digest.last_edit_timestamp);
|
||||||
let local_mt = modified_time.duration_since(UNIX_EPOCH)?;
|
let local_mt = modified_time.duration_since(UNIX_EPOCH)?;
|
||||||
println!(
|
log::info!(
|
||||||
"{:?}:rm:{},lm:{},rf:{},lf:{}",
|
"{:?}:rm:{},lm:{},rf:{},lf:{}",
|
||||||
path,
|
path,
|
||||||
remote_mt.as_secs(),
|
remote_mt.as_secs(),
|
||||||
@ -693,15 +702,17 @@ pub fn is_write_need_confirmation(
|
|||||||
digest.file_size,
|
digest.file_size,
|
||||||
metadata.len()
|
metadata.len()
|
||||||
);
|
);
|
||||||
// if
|
|
||||||
// is_recv && remote_mt >= local_mt) || (!is_recv && remote_mt <= local_mt) ||
|
|
||||||
if remote_mt == local_mt && digest.file_size == metadata.len() {
|
if remote_mt == local_mt && digest.file_size == metadata.len() {
|
||||||
// I'm recving or sending an newer modified file!
|
return Ok(None);
|
||||||
// or a
|
|
||||||
return Ok(false);
|
|
||||||
}
|
}
|
||||||
Ok(true)
|
Ok(Some(FileTransferDigest {
|
||||||
|
id: digest.id,
|
||||||
|
file_num: digest.file_num,
|
||||||
|
last_edit_timestamp: local_mt.as_secs(),
|
||||||
|
file_size: metadata.len(),
|
||||||
|
..Default::default()
|
||||||
|
}))
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -955,7 +955,7 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(message::Union::file_action(fa)) => {
|
Some(message::Union::file_action(fa)) => {
|
||||||
println!("recv file_action, {:?}", fa);
|
log::info!("recv file_action, {:?}", fa);
|
||||||
if self.file_transfer.is_some() {
|
if self.file_transfer.is_some() {
|
||||||
match fa.union {
|
match fa.union {
|
||||||
Some(file_action::Union::read_dir(rd)) => {
|
Some(file_action::Union::read_dir(rd)) => {
|
||||||
@ -988,7 +988,6 @@ impl Connection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(file_action::Union::receive(r)) => {
|
Some(file_action::Union::receive(r)) => {
|
||||||
println!("[connection.rs:891] recv FileTransferReceiveRequest");
|
|
||||||
self.send_fs(ipc::FS::NewWrite {
|
self.send_fs(ipc::FS::NewWrite {
|
||||||
path: r.path,
|
path: r.path,
|
||||||
id: r.id,
|
id: r.id,
|
||||||
@ -1025,7 +1024,6 @@ impl Connection {
|
|||||||
fs::remove_job(c.id, &mut self.read_jobs);
|
fs::remove_job(c.id, &mut self.read_jobs);
|
||||||
}
|
}
|
||||||
Some(file_action::Union::send_confirm(r)) => {
|
Some(file_action::Union::send_confirm(r)) => {
|
||||||
println!("recv send confirm request");
|
|
||||||
if let Some(job) = fs::get_job(r.id, &mut self.read_jobs) {
|
if let Some(job) = fs::get_job(r.id, &mut self.read_jobs) {
|
||||||
job.confirm(&r);
|
job.confirm(&r);
|
||||||
}
|
}
|
||||||
|
49
src/ui/cm.rs
49
src/ui/cm.rs
@ -3,6 +3,8 @@ use crate::ipc::{self, new_listener, Connection, Data};
|
|||||||
use clipboard::{
|
use clipboard::{
|
||||||
create_cliprdr_context, empty_clipboard, get_rx_clip_client, server_clip_file, set_conn_enabled,
|
create_cliprdr_context, empty_clipboard, get_rx_clip_client, server_clip_file, set_conn_enabled,
|
||||||
};
|
};
|
||||||
|
use hbb_common::fs::{get_string, is_write_need_confirmation, new_send_confirm};
|
||||||
|
use hbb_common::log::log;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
allow_err,
|
allow_err,
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -10,6 +12,7 @@ use hbb_common::{
|
|||||||
message_proto::*,
|
message_proto::*,
|
||||||
protobuf::Message as _,
|
protobuf::Message as _,
|
||||||
tokio::{self, sync::mpsc, task::spawn_blocking},
|
tokio::{self, sync::mpsc, task::spawn_blocking},
|
||||||
|
ResultType,
|
||||||
};
|
};
|
||||||
use sciter::{make_args, Element, Value, HELEMENT};
|
use sciter::{make_args, Element, Value, HELEMENT};
|
||||||
use std::{
|
use std::{
|
||||||
@ -188,21 +191,45 @@ impl ConnectionManager {
|
|||||||
modified_time,
|
modified_time,
|
||||||
} => {
|
} => {
|
||||||
if let Some(job) = fs::get_job(id, write_jobs) {
|
if let Some(job) = fs::get_job(id, write_jobs) {
|
||||||
// TODO
|
let mut req = FileTransferSendConfirmRequest {
|
||||||
let mut msg_out = Message::new();
|
|
||||||
let mut file_action = FileAction::new();
|
|
||||||
file_action.set_send_confirm(FileTransferSendConfirmRequest {
|
|
||||||
id,
|
id,
|
||||||
file_num,
|
file_num,
|
||||||
union: Some(file_transfer_send_confirm_request::Union::offset_blk(0)),
|
union: Some(file_transfer_send_confirm_request::Union::offset_blk(0)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
};
|
||||||
msg_out.set_file_action(file_action);
|
let digest = FileTransferDigest {
|
||||||
println!(
|
id,
|
||||||
"[CHECK DIGEST] dig dest recved. confirmed. msg: {:?}",
|
file_num,
|
||||||
msg_out
|
last_edit_timestamp: modified_time,
|
||||||
);
|
file_size,
|
||||||
Self::send(msg_out, conn).await;
|
..Default::default()
|
||||||
|
};
|
||||||
|
if let Some(file) = job.files().get(file_num as usize) {
|
||||||
|
let path = get_string(&job.join(&file.name));
|
||||||
|
match is_write_need_confirmation(&path, &digest) {
|
||||||
|
Ok(digest) => {
|
||||||
|
if digest.is_none() {
|
||||||
|
log::info!("skip job {}, file_num {}", id, file_num);
|
||||||
|
req.set_skip(true);
|
||||||
|
let msg_out = new_send_confirm(req);
|
||||||
|
Self::send(msg_out, conn).await;
|
||||||
|
} else {
|
||||||
|
// upload to server, but server has the same file, request
|
||||||
|
println!(
|
||||||
|
"server has the same file, send server digest to local"
|
||||||
|
);
|
||||||
|
let mut msg_out = Message::new();
|
||||||
|
let mut fr = FileResponse::new();
|
||||||
|
fr.set_digest(digest.unwrap());
|
||||||
|
msg_out.set_file_response(fr);
|
||||||
|
Self::send(msg_out, conn).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Self::send(fs::new_error(id, err, file_num), conn).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ipc::FS::WriteBlock {
|
ipc::FS::WriteBlock {
|
||||||
|
@ -11,7 +11,7 @@ use clipboard::{
|
|||||||
get_rx_clip_client, server_clip_file,
|
get_rx_clip_client, server_clip_file,
|
||||||
};
|
};
|
||||||
use enigo::{self, Enigo, KeyboardControllable};
|
use enigo::{self, Enigo, KeyboardControllable};
|
||||||
use hbb_common::fs::{get_string, is_file_exists};
|
use hbb_common::fs::{get_string, is_file_exists, new_send_confirm};
|
||||||
use hbb_common::log::log;
|
use hbb_common::log::log;
|
||||||
use hbb_common::{
|
use hbb_common::{
|
||||||
allow_err,
|
allow_err,
|
||||||
@ -1760,7 +1760,7 @@ impl Remote {
|
|||||||
|
|
||||||
async fn handle_msg_from_peer(&mut self, data: &[u8], peer: &mut Stream) -> bool {
|
async fn handle_msg_from_peer(&mut self, data: &[u8], peer: &mut Stream) -> bool {
|
||||||
if let Ok(msg_in) = Message::parse_from_bytes(&data) {
|
if let Ok(msg_in) = Message::parse_from_bytes(&data) {
|
||||||
println!("recved msg from peer, decoded: {:?}", msg_in);
|
// println!("recved msg from peer, decoded: {:?}", msg_in);
|
||||||
match msg_in.union {
|
match msg_in.union {
|
||||||
Some(message::Union::video_frame(vf)) => {
|
Some(message::Union::video_frame(vf)) => {
|
||||||
if !self.first_frame {
|
if !self.first_frame {
|
||||||
@ -1841,14 +1841,13 @@ impl Remote {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(file_response::Union::digest(digest)) => {
|
Some(file_response::Union::digest(digest)) => {
|
||||||
log::info!("recv file transfer digest");
|
|
||||||
if let Some(job) = fs::get_job(digest.id, &mut self.write_jobs) {
|
if let Some(job) = fs::get_job(digest.id, &mut self.write_jobs) {
|
||||||
if let Some(file) = job.files().get(digest.file_num as usize) {
|
if let Some(file) = job.files().get(digest.file_num as usize) {
|
||||||
let write_path = get_string(&job.join(&file.name));
|
let write_path = get_string(&job.join(&file.name));
|
||||||
let overwrite_strategy = job.default_overwrite_strategy();
|
let overwrite_strategy = job.default_overwrite_strategy();
|
||||||
match fs::is_write_need_confirmation(&write_path, &digest) {
|
match fs::is_write_need_confirmation(&write_path, &digest) {
|
||||||
Ok(res) => {
|
Ok(res) => {
|
||||||
if res {
|
if res.is_some() {
|
||||||
// need confirm
|
// need confirm
|
||||||
if overwrite_strategy.is_none() {
|
if overwrite_strategy.is_none() {
|
||||||
self.handler.call(
|
self.handler.call(
|
||||||
@ -1860,36 +1859,27 @@ impl Remote {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
let mut msg = Message::new();
|
let msg = new_send_confirm(
|
||||||
let mut file_action = FileAction::new();
|
FileTransferSendConfirmRequest {
|
||||||
file_action
|
|
||||||
.set_send_confirm(FileTransferSendConfirmRequest {
|
|
||||||
id: digest.id,
|
id: digest.id,
|
||||||
file_num: digest.file_num,
|
file_num: digest.file_num,
|
||||||
union: Some(
|
union: if overwrite_strategy.unwrap() {
|
||||||
if overwrite_strategy.unwrap() {
|
Some(file_transfer_send_confirm_request::Union::offset_blk(0))
|
||||||
file_transfer_send_confirm_request::Union::offset_blk(0)
|
} else {
|
||||||
} else {
|
Some(file_transfer_send_confirm_request::Union::skip(true))
|
||||||
file_transfer_send_confirm_request::Union::skip(true)
|
},
|
||||||
},
|
|
||||||
),
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
},
|
||||||
msg.set_file_action(file_action);
|
);
|
||||||
allow_err!(peer.send(&msg).await);
|
allow_err!(peer.send(&msg).await);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// file with digest need send
|
let msg= new_send_confirm(FileTransferSendConfirmRequest {
|
||||||
let mut msg = Message::new();
|
|
||||||
let mut file_action = FileAction::new();
|
|
||||||
file_action
|
|
||||||
.set_send_confirm(FileTransferSendConfirmRequest {
|
|
||||||
id: digest.id,
|
id: digest.id,
|
||||||
file_num: digest.file_num,
|
file_num: digest.file_num,
|
||||||
union: Some(file_transfer_send_confirm_request::Union::offset_blk(0)),
|
union: Some(file_transfer_send_confirm_request::Union::skip(true)),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
msg.set_file_action(file_action);
|
|
||||||
allow_err!(peer.send(&msg).await);
|
allow_err!(peer.send(&msg).await);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user