处理0字节临时文件
This commit is contained in:
@@ -1243,7 +1243,10 @@ fn scan_local_tmp_files(app_name: &str) -> Vec<(String, u64)> {
|
|||||||
.unwrap_or(&rel_str);
|
.unwrap_or(&rel_str);
|
||||||
// 获取文件大小
|
// 获取文件大小
|
||||||
if let Ok(metadata) = fs::metadata(&path) {
|
if let Ok(metadata) = fs::metadata(&path) {
|
||||||
tmp_files.push((official_name.to_string(), metadata.len()));
|
// 跳过 0 字节的临时文件(MD5 无意义,视为从头续传)
|
||||||
|
if metadata.len() > 0 {
|
||||||
|
tmp_files.push((official_name.to_string(), metadata.len()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1760,22 +1763,28 @@ async fn run_updater(debug_mode: bool) -> bool {
|
|||||||
let tmp_path = upgrade_base.join(&tmp_filename);
|
let tmp_path = upgrade_base.join(&tmp_filename);
|
||||||
let has_tmp = tmp_path.exists();
|
let has_tmp = tmp_path.exists();
|
||||||
let has_official = file_path.exists();
|
let has_official = file_path.exists();
|
||||||
|
let tmp_is_zero = has_tmp && tmp_path.metadata().map(|m| m.len() == 0).unwrap_or(false);
|
||||||
|
|
||||||
if has_tmp {
|
if has_tmp {
|
||||||
// 情况A:本地有临时文件 → 比较临时文件
|
if tmp_is_zero {
|
||||||
let local_md5 = compute_file_md5(&tmp_path);
|
// 情况0:本地有 0 字节临时文件(0 字节未上报服务端,无法比对 MD5)
|
||||||
if let Some(lm) = local_md5 {
|
// 直接从 offset 0 断点续传
|
||||||
if &lm != server_md5 {
|
request_download_for_app(&sender, &app_name, filename, 0);
|
||||||
// MD5 不对 → 清空临时文件内容
|
update_performed_clone2.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
log_print!("{} [AllFile] tmp {} MD5不一致 (本地={}, 服务端={}),清空", ts, tmp_filename, lm, server_md5);
|
} else {
|
||||||
if let Ok(file) = fs::File::create(&tmp_path) {
|
// 情况A:本地有临时文件(>0字节)→ 比较临时文件
|
||||||
let _ = file.set_len(0);
|
let local_md5 = compute_file_md5(&tmp_path);
|
||||||
|
if let Some(lm) = local_md5 {
|
||||||
|
if &lm != server_md5 {
|
||||||
|
log_print!("{} [AllFile] tmp {} MD5不一致 (本地={}, 服务端={}),清空", ts, tmp_filename, lm, server_md5);
|
||||||
|
if let Ok(file) = fs::File::create(&tmp_path) {
|
||||||
|
let _ = file.set_len(0);
|
||||||
|
}
|
||||||
|
request_download_for_app(&sender, &app_name, filename, 0);
|
||||||
|
update_performed_clone2.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||||
|
} else {
|
||||||
|
log_print!("{} [AllFile] tmp {} MD5一致,续传", ts, tmp_filename);
|
||||||
}
|
}
|
||||||
// 发送下载请求
|
|
||||||
request_download_for_app(&sender, &app_name, filename, 0);
|
|
||||||
update_performed_clone2.store(true, std::sync::atomic::Ordering::SeqCst);
|
|
||||||
} else {
|
|
||||||
log_print!("{} [AllFile] tmp {} MD5一致,续传", ts, tmp_filename);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if has_official {
|
} else if has_official {
|
||||||
@@ -1783,7 +1792,6 @@ async fn run_updater(debug_mode: bool) -> bool {
|
|||||||
let local_md5 = compute_file_md5(&file_path);
|
let local_md5 = compute_file_md5(&file_path);
|
||||||
if let Some(lm) = local_md5 {
|
if let Some(lm) = local_md5 {
|
||||||
if &lm != server_md5 {
|
if &lm != server_md5 {
|
||||||
// MD5 不对 → 创建空的临时文件
|
|
||||||
log_print!("{} [AllFile] {} MD5不一致 (本地={}, 服务端={}),创建 tmp", ts, filename, lm, server_md5);
|
log_print!("{} [AllFile] {} MD5不一致 (本地={}, 服务端={}),创建 tmp", ts, filename, lm, server_md5);
|
||||||
if let Some(parent) = tmp_path.parent() {
|
if let Some(parent) = tmp_path.parent() {
|
||||||
let _ = fs::create_dir_all(parent);
|
let _ = fs::create_dir_all(parent);
|
||||||
@@ -1811,13 +1819,16 @@ async fn run_updater(debug_mode: bool) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. 为剩余的有效临时文件发送续传请求
|
// 4. 为有效的临时文件(>0字节)发送续传请求
|
||||||
for (filename, _, _) in &server_files {
|
for (filename, _, _) in &server_files {
|
||||||
let tmp_filename = format!("{}.tmp", filename);
|
let tmp_filename = format!("{}.tmp", filename);
|
||||||
let tmp_path = upgrade_base.join(&tmp_filename);
|
let tmp_path = upgrade_base.join(&tmp_filename);
|
||||||
if tmp_path.exists() {
|
if tmp_path.exists() {
|
||||||
// tmp 存在,发送续传请求
|
|
||||||
let file_size = fs::metadata(&tmp_path).map(|m| m.len()).unwrap_or(0);
|
let file_size = fs::metadata(&tmp_path).map(|m| m.len()).unwrap_or(0);
|
||||||
|
// 0 字节 tmp 已在步骤3中处理过,跳过
|
||||||
|
if file_size == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
request_download_for_app(&sender, &app_name, filename, file_size);
|
request_download_for_app(&sender, &app_name, filename, file_size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user