mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-03-22 12:41:14 +03:00
feat: windows, custom client, update (#13687)
Signed-off-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -53,8 +53,25 @@ pub fn download_file(
|
||||
auto_del_dur: Option<Duration>,
|
||||
) -> ResultType<String> {
|
||||
let id = url.clone();
|
||||
if DOWNLOADERS.lock().unwrap().contains_key(&id) {
|
||||
return Ok(id);
|
||||
// First pass: if a non-error downloader exists for this URL, reuse it.
|
||||
// If an errored downloader exists, remove it so this call can retry.
|
||||
let mut stale_path = None;
|
||||
{
|
||||
let mut downloaders = DOWNLOADERS.lock().unwrap();
|
||||
if let Some(downloader) = downloaders.get(&id) {
|
||||
if downloader.error.is_none() {
|
||||
return Ok(id);
|
||||
}
|
||||
stale_path = downloader.path.clone();
|
||||
downloaders.remove(&id);
|
||||
}
|
||||
}
|
||||
if let Some(p) = stale_path {
|
||||
if p.exists() {
|
||||
if let Err(e) = std::fs::remove_file(&p) {
|
||||
log::warn!("Failed to remove stale download file {}: {}", p.display(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(path) = path.as_ref() {
|
||||
@@ -75,8 +92,26 @@ pub fn download_file(
|
||||
tx_cancel: tx,
|
||||
finished: false,
|
||||
};
|
||||
let mut downloaders = DOWNLOADERS.lock().unwrap();
|
||||
downloaders.insert(id.clone(), downloader);
|
||||
// Second pass (atomic with insert) to avoid race with another concurrent caller.
|
||||
let mut stale_path_after_check = None;
|
||||
{
|
||||
let mut downloaders = DOWNLOADERS.lock().unwrap();
|
||||
if let Some(existing) = downloaders.get(&id) {
|
||||
if existing.error.is_none() {
|
||||
return Ok(id);
|
||||
}
|
||||
stale_path_after_check = existing.path.clone();
|
||||
downloaders.remove(&id);
|
||||
}
|
||||
downloaders.insert(id.clone(), downloader);
|
||||
}
|
||||
if let Some(p) = stale_path_after_check {
|
||||
if p.exists() {
|
||||
if let Err(e) = std::fs::remove_file(&p) {
|
||||
log::warn!("Failed to remove stale download file {}: {}", p.display(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let id2 = id.clone();
|
||||
std::thread::spawn(
|
||||
|
||||
Reference in New Issue
Block a user