mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-24 20:53:18 +08:00
add: overwrite version limit, remove debug log
This commit is contained in:
parent
050952e5e8
commit
4975c9b54d
@ -1,4 +1,4 @@
|
||||
use crate::{bail, message_proto::*, ResultType, Stream};
|
||||
use crate::{bail, get_version_number, message_proto::*, ResultType, Stream};
|
||||
use std::path::{Path, PathBuf};
|
||||
// https://doc.rust-lang.org/std/os/windows/fs/trait.MetadataExt.html
|
||||
use crate::{
|
||||
@ -191,6 +191,10 @@ pub fn is_file_exists(file_path: &str) -> bool {
|
||||
return Path::new(file_path).exists();
|
||||
}
|
||||
|
||||
pub fn can_enable_overwrite_detection(version: i64) -> bool {
|
||||
version >= get_version_number("1.1.9")
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TransferJob {
|
||||
id: i32,
|
||||
@ -201,6 +205,7 @@ pub struct TransferJob {
|
||||
total_size: u64,
|
||||
finished_size: u64,
|
||||
transferred: u64,
|
||||
enable_overwrite_detection: bool,
|
||||
file_confirmed: bool,
|
||||
file_is_waiting: bool,
|
||||
default_overwrite_strategy: Option<bool>,
|
||||
@ -229,20 +234,31 @@ fn is_compressed_file(name: &str) -> bool {
|
||||
}
|
||||
|
||||
impl TransferJob {
|
||||
pub fn new_write(id: i32, path: String, files: Vec<FileEntry>) -> Self {
|
||||
println!("new write {}", path);
|
||||
pub fn new_write(
|
||||
id: i32,
|
||||
path: String,
|
||||
files: Vec<FileEntry>,
|
||||
enable_override_detection: bool,
|
||||
) -> Self {
|
||||
log::info!("new write {}", path);
|
||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
||||
Self {
|
||||
id,
|
||||
path: get_path(&path),
|
||||
files,
|
||||
total_size,
|
||||
enable_overwrite_detection: enable_override_detection,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_read(id: i32, path: String, include_hidden: bool) -> ResultType<Self> {
|
||||
println!("new read {}", path);
|
||||
pub fn new_read(
|
||||
id: i32,
|
||||
path: String,
|
||||
include_hidden: bool,
|
||||
enable_override_detection: bool,
|
||||
) -> ResultType<Self> {
|
||||
log::info!("new read {}", path);
|
||||
let files = get_recursive_files(&path, include_hidden)?;
|
||||
let total_size = files.iter().map(|x| x.size as u64).sum();
|
||||
Ok(Self {
|
||||
@ -250,6 +266,7 @@ impl TransferJob {
|
||||
path: get_path(&path),
|
||||
files,
|
||||
total_size,
|
||||
enable_overwrite_detection: enable_override_detection,
|
||||
..Default::default()
|
||||
})
|
||||
}
|
||||
@ -315,7 +332,6 @@ impl TransferJob {
|
||||
}
|
||||
|
||||
pub async fn write(&mut self, block: FileTransferBlock, raw: Option<&[u8]>) -> ResultType<()> {
|
||||
println!("write file transfer blk[{},{}]", block.id, block.file_num);
|
||||
if block.id != self.id {
|
||||
bail!("Wrong id");
|
||||
}
|
||||
@ -385,12 +401,14 @@ impl TransferJob {
|
||||
}
|
||||
}
|
||||
}
|
||||
if !self.file_confirmed() {
|
||||
if !self.file_is_waiting() {
|
||||
self.send_current_digest(stream).await?;
|
||||
self.set_file_is_waiting(true);
|
||||
if self.enable_overwrite_detection {
|
||||
if !self.file_confirmed() {
|
||||
if !self.file_is_waiting() {
|
||||
self.send_current_digest(stream).await?;
|
||||
self.set_file_is_waiting(true);
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
return Ok(None);
|
||||
}
|
||||
const BUF_SIZE: usize = 128 * 1024;
|
||||
let mut buf: Vec<u8> = Vec::with_capacity(BUF_SIZE);
|
||||
@ -459,9 +477,11 @@ impl TransferJob {
|
||||
});
|
||||
msg.set_file_response(resp);
|
||||
stream.send(&msg).await?;
|
||||
println!(
|
||||
log::info!(
|
||||
"id: {}, file_num:{}, digest message is sent. waiting for confirm. msg: {:?}",
|
||||
self.id, self.file_num, msg
|
||||
self.id,
|
||||
self.file_num,
|
||||
msg
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@ -500,19 +520,19 @@ impl TransferJob {
|
||||
|
||||
pub fn confirm(&mut self, r: &FileTransferSendConfirmRequest) -> bool {
|
||||
if self.file_num() != r.file_num {
|
||||
log::debug!("file num truncated, ignoring");
|
||||
log::info!("file num truncated, ignoring");
|
||||
} else {
|
||||
match r.union {
|
||||
Some(file_transfer_send_confirm_request::Union::skip(s)) => {
|
||||
if s {
|
||||
println!("skip current file");
|
||||
log::info!("skip file id:{}, file_num:{}", r.id, r.file_num);
|
||||
self.skip_current_file();
|
||||
} else {
|
||||
self.set_file_confirmed(true);
|
||||
}
|
||||
}
|
||||
Some(file_transfer_send_confirm_request::Union::offset_blk(offset)) => {
|
||||
println!("file confirmed");
|
||||
log::info!("file confirmed");
|
||||
self.set_file_confirmed(true);
|
||||
}
|
||||
_ => {}
|
||||
@ -538,7 +558,6 @@ pub fn new_error<T: std::string::ToString>(id: i32, err: T, file_num: i32) -> Me
|
||||
|
||||
#[inline]
|
||||
pub fn new_dir(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
||||
println!("[fs.rs:510] create new dir");
|
||||
let mut resp = FileResponse::new();
|
||||
resp.set_dir(FileDirectory {
|
||||
id,
|
||||
@ -585,7 +604,7 @@ pub fn new_receive(id: i32, path: String, files: Vec<FileEntry>) -> Message {
|
||||
|
||||
#[inline]
|
||||
pub fn new_send(id: i32, path: String, include_hidden: bool) -> Message {
|
||||
println!("new send: {},id : {}", path, id);
|
||||
log::info!("new send: {},id : {}", path, id);
|
||||
let mut action = FileAction::new();
|
||||
action.set_send(FileTransferSendRequest {
|
||||
id,
|
||||
@ -638,7 +657,8 @@ pub async fn handle_read_jobs(
|
||||
stream.send(&new_block(block)).await?;
|
||||
}
|
||||
Ok(None) => {
|
||||
if !job.file_confirmed && !job.file_is_waiting {
|
||||
if !job.enable_overwrite_detection || (!job.file_confirmed && !job.file_is_waiting)
|
||||
{
|
||||
finished.push(job.id());
|
||||
stream.send(&new_done(job.id(), job.file_num())).await?;
|
||||
} else {
|
||||
|
@ -12,6 +12,7 @@ use hbb_common::{
|
||||
config::Config,
|
||||
fs,
|
||||
futures::{SinkExt, StreamExt},
|
||||
get_version_number,
|
||||
message_proto::{option_message::BoolOption, permission_info::Permission},
|
||||
sleep, timeout,
|
||||
tokio::{
|
||||
@ -893,7 +894,6 @@ impl Connection {
|
||||
}
|
||||
}
|
||||
} else if self.authorized {
|
||||
// println!("on_message: {:?}", msg);
|
||||
match msg.union {
|
||||
Some(message::Union::mouse_event(me)) => {
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
@ -973,9 +973,9 @@ impl Connection {
|
||||
}
|
||||
Some(file_action::Union::send(s)) => {
|
||||
let id = s.id;
|
||||
let path = s.path;
|
||||
match fs::TransferJob::new_read(id, path.clone(), s.include_hidden)
|
||||
{
|
||||
let od =
|
||||
can_enable_overwrite_detection(get_version_number(VERSION));
|
||||
match fs::TransferJob::new_read(id, s.path.clone(), s.include_hidden) {
|
||||
Err(err) => {
|
||||
self.send(fs::new_error(id, err, 0)).await;
|
||||
}
|
||||
@ -1195,7 +1195,6 @@ impl Connection {
|
||||
}
|
||||
|
||||
fn read_dir(&mut self, dir: &str, include_hidden: bool) {
|
||||
// println!("[connection.rs:1130] read_dir");
|
||||
let dir = dir.to_string();
|
||||
self.send_fs(ipc::FS::ReadDir {
|
||||
dir,
|
||||
|
11
src/ui/cm.rs
11
src/ui/cm.rs
@ -1,14 +1,17 @@
|
||||
use crate::ipc::{self, new_listener, Connection, Data};
|
||||
use crate::VERSION;
|
||||
#[cfg(windows)]
|
||||
use clipboard::{
|
||||
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::fs::{
|
||||
can_enable_overwrite_detection, get_string, is_write_need_confirmation, new_send_confirm,
|
||||
};
|
||||
use hbb_common::log::log;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
config::Config,
|
||||
fs, log,
|
||||
fs, get_version_number, log,
|
||||
message_proto::*,
|
||||
protobuf::Message as _,
|
||||
tokio::{self, sync::mpsc, task::spawn_blocking},
|
||||
@ -156,6 +159,7 @@ impl ConnectionManager {
|
||||
id,
|
||||
mut files,
|
||||
} => {
|
||||
let od = can_enable_overwrite_detection(get_version_number(VERSION));
|
||||
write_jobs.push(fs::TransferJob::new_write(
|
||||
id,
|
||||
path,
|
||||
@ -167,6 +171,7 @@ impl ConnectionManager {
|
||||
..Default::default()
|
||||
})
|
||||
.collect(),
|
||||
od,
|
||||
));
|
||||
}
|
||||
ipc::FS::CancelWrite { id } => {
|
||||
@ -210,7 +215,7 @@ impl ConnectionManager {
|
||||
if let Some(mut digest) = digest {
|
||||
// upload to server, but server has the same file, request
|
||||
digest.is_upload = is_upload;
|
||||
println!(
|
||||
log::info!(
|
||||
"server has the same file, send server digest to local"
|
||||
);
|
||||
let mut msg_out = Message::new();
|
||||
|
@ -679,7 +679,6 @@ function confirmDelete(id ,path, is_remote) {
|
||||
}
|
||||
|
||||
handler.confirmDeleteFiles = function(id, i, name) {
|
||||
stdout.println("id=" + id +", i=" +",name="+name);
|
||||
var jt = file_transfer.job_table;
|
||||
var job = jt.job_map[id];
|
||||
if (!job) return;
|
||||
@ -695,6 +694,7 @@ handler.confirmDeleteFiles = function(id, i, name) {
|
||||
</div>", function(res=null) {
|
||||
if (!res) {
|
||||
jt.updateJobStatus(id, i - 1, "cancel");
|
||||
file_transfer.job_table.confirmDeletePolling();
|
||||
} else if (res.skip) {
|
||||
if (res.remember){
|
||||
jt.updateJobStatus(id, i, "cancel");
|
||||
@ -718,9 +718,6 @@ handler.confirmDeleteFiles = function(id, i, name) {
|
||||
|
||||
handler.overrideFileConfirm = function(id, file_num, to, is_upload) {
|
||||
var jt = file_transfer.job_table;
|
||||
var job = jt.job_map[id];
|
||||
stdout.println("job type: " + job.type);
|
||||
stdout.println(JSON.stringify(job));
|
||||
msgbox("custom-skip", "Confirm Write Strategy", "<div .form> \
|
||||
<div>" + translate('Overwrite') + translate('files') + ".</div> \
|
||||
<div>" + translate('This file exists, skip or overwrite this file?') + "</div> \
|
||||
|
@ -11,7 +11,9 @@ use clipboard::{
|
||||
get_rx_clip_client, server_clip_file,
|
||||
};
|
||||
use enigo::{self, Enigo, KeyboardControllable};
|
||||
use hbb_common::fs::{get_string, is_file_exists, new_send_confirm};
|
||||
use hbb_common::fs::{
|
||||
can_enable_overwrite_detection, get_string, is_file_exists, new_send_confirm,
|
||||
};
|
||||
use hbb_common::log::log;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
@ -1537,25 +1539,27 @@ impl Remote {
|
||||
allow_err!(peer.send(&msg).await);
|
||||
}
|
||||
Data::SendFiles((id, path, to, include_hidden, is_remote)) => {
|
||||
println!("send files, is remote {}", is_remote);
|
||||
log::info!("send files, is remote {}", is_remote);
|
||||
let od = can_enable_overwrite_detection(self.handler.lc.read().unwrap().version);
|
||||
if is_remote {
|
||||
println!("New job {}, write to {} from remote {}", id, to, path);
|
||||
log::debug!("New job {}, write to {} from remote {}", id, to, path);
|
||||
self.write_jobs
|
||||
.push(fs::TransferJob::new_write(id, to, Vec::new()));
|
||||
.push(fs::TransferJob::new_write(id, to, Vec::new(), od));
|
||||
allow_err!(peer.send(&fs::new_send(id, path, include_hidden)).await);
|
||||
} else {
|
||||
match fs::TransferJob::new_read(id, path.clone(), include_hidden) {
|
||||
match fs::TransferJob::new_read(id, path.clone(), include_hidden, od) {
|
||||
Err(err) => {
|
||||
self.handle_job_status(id, -1, Some(err.to_string()));
|
||||
}
|
||||
Ok(job) => {
|
||||
println!(
|
||||
log::debug!(
|
||||
"New job {}, read {} to remote {}, {} files",
|
||||
id,
|
||||
path,
|
||||
to,
|
||||
job.files().len()
|
||||
);
|
||||
let config = self.handler.lc.read().unwrap().version;
|
||||
let m = make_fd(job.id(), job.files(), true);
|
||||
self.handler.call("updateFolderFiles", &make_args!(m));
|
||||
let files = job.files().clone();
|
||||
@ -1780,7 +1784,6 @@ impl Remote {
|
||||
|
||||
async fn handle_msg_from_peer(&mut self, data: &[u8], peer: &mut Stream) -> bool {
|
||||
if let Ok(msg_in) = Message::parse_from_bytes(&data) {
|
||||
// println!("recved msg from peer, decoded: {:?}", msg_in);
|
||||
match msg_in.union {
|
||||
Some(message::Union::video_frame(vf)) => {
|
||||
if !self.first_frame {
|
||||
@ -1928,13 +1931,11 @@ impl Remote {
|
||||
if let Some(job) = fs::get_job(block.id, &mut self.write_jobs) {
|
||||
if let Err(_err) = job.write(block, None).await {
|
||||
// to-do: add "skip" for writing job
|
||||
println!("error: {}", _err);
|
||||
}
|
||||
self.update_jobs_status();
|
||||
}
|
||||
}
|
||||
Some(file_response::Union::done(d)) => {
|
||||
log::info!("file response done");
|
||||
if let Some(job) = fs::get_job(d.id, &mut self.write_jobs) {
|
||||
job.modify_time();
|
||||
fs::remove_job(d.id, &mut self.write_jobs);
|
||||
|
Loading…
Reference in New Issue
Block a user