opt: name, imports

This commit is contained in:
Kingtous 2022-04-29 16:47:45 +08:00
parent 265e3c760e
commit 02f214e39a
6 changed files with 11 additions and 24 deletions

View File

@ -270,7 +270,7 @@ message FileResponse {
message FileTransferDigest {
int32 id = 1;
sint32 file_num = 2;
uint64 last_edit_timestamp = 3;
uint64 last_modified = 3;
uint64 file_size = 4;
bool is_upload = 5;
}

View File

@ -5,7 +5,6 @@ use crate::{
compress::{compress, decompress},
config::{Config, COMPRESS_LEVEL},
};
use log::log;
#[cfg(windows)]
use std::os::windows::prelude::*;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
@ -472,7 +471,7 @@ impl TransferJob {
resp.set_digest(FileTransferDigest {
id: self.id,
file_num: self.file_num,
last_edit_timestamp: last_modified,
last_modified,
file_size: meta.len(),
..Default::default()
});
@ -647,7 +646,6 @@ pub async fn handle_read_jobs(
) -> ResultType<()> {
let mut finished = Vec::new();
for job in jobs.iter_mut() {
// println!("[fs.rs:588] handle_read_jobs. {:?}", job.id);
match job.read(stream).await {
Err(err) => {
stream
@ -663,7 +661,7 @@ pub async fn handle_read_jobs(
finished.push(job.id());
stream.send(&new_done(job.id(), job.file_num())).await?;
} else {
log::info!("waiting confirmation.");
// waiting confirmation.
}
}
}
@ -718,23 +716,15 @@ pub fn is_write_need_confirmation(
if path.exists() && path.is_file() {
let metadata = std::fs::metadata(path)?;
let modified_time = metadata.modified()?;
let remote_mt = Duration::from_secs(digest.last_edit_timestamp);
let remote_mt = Duration::from_secs(digest.last_modified);
let local_mt = modified_time.duration_since(UNIX_EPOCH)?;
log::info!(
"{:?}:rm:{},lm:{},rf:{},lf:{}",
path,
remote_mt.as_secs(),
local_mt.as_secs(),
digest.file_size,
metadata.len()
);
if remote_mt == local_mt && digest.file_size == metadata.len() {
return Ok(DigestCheckResult::IsSame);
}
Ok(DigestCheckResult::NeedConfirm(FileTransferDigest {
id: digest.id,
file_num: digest.file_num,
last_edit_timestamp: local_mt.as_secs(),
last_modified: local_mt.as_secs(),
file_size: metadata.len(),
..Default::default()
}))

View File

@ -63,7 +63,7 @@ pub enum FS {
id: i32,
file_num: i32,
file_size: u64,
modified_time: u64,
last_modified: u64,
is_upload: bool,
},
}

View File

@ -955,7 +955,6 @@ impl Connection {
}
}
Some(message::Union::file_action(fa)) => {
log::info!("recv file_action, {:?}", fa);
if self.file_transfer.is_some() {
match fa.union {
Some(file_action::Union::read_dir(rd)) => {
@ -1051,7 +1050,7 @@ impl Connection {
id: d.id,
file_num: d.file_num,
file_size: d.file_size,
modified_time: d.last_edit_timestamp,
last_modified: d.last_modified,
is_upload: true,
}),
_ => {}

View File

@ -192,7 +192,7 @@ impl ConnectionManager {
id,
file_num,
file_size,
modified_time,
last_modified,
is_upload,
} => {
if let Some(job) = fs::get_job(id, write_jobs) {
@ -205,7 +205,7 @@ impl ConnectionManager {
let digest = FileTransferDigest {
id,
file_num,
last_edit_timestamp: modified_time,
last_modified,
file_size,
..Default::default()
};
@ -222,9 +222,6 @@ impl ConnectionManager {
DigestCheckResult::NeedConfirm(mut digest) => {
// upload to server, but server has the same file, request
digest.is_upload = is_upload;
log::info!(
"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);
@ -365,6 +362,7 @@ impl ConnectionManager {
}
async fn send(msg: Message, conn: &mut Connection) {
println!("send msg: {:?}", msg);
match msg.write_to_bytes() {
Ok(bytes) => allow_err!(conn.send(&Data::RawMessage(bytes)).await),
err => allow_err!(err),

View File

@ -768,6 +768,7 @@ impl Handler {
}
fn reconnect(&mut self) {
println!("reconnecting");
let cloned = self.clone();
let mut lock = self.write().unwrap();
lock.thread.take().map(|t| t.join());
@ -1559,7 +1560,6 @@ impl Remote {
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();