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