fix(tabby-download): even when prefer_local_file is set to true, we should still check for remote (if network is avaialble), to see if a file should be upgraded (#500)

release-0.2
Meng Zhang 2023-10-03 07:09:57 +08:00 committed by GitHub
parent 80a17aea37
commit 63612d5a67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 17 deletions

View File

@ -93,28 +93,22 @@ async fn download_model_file(
let filepath = ModelDir::new(model_id).path_string(path); let filepath = ModelDir::new(model_id).path_string(path);
// Cache hit. // Cache hit.
let local_file_ready = if prefer_local_file { let local_file_ready = if let Some(local_cache_key) = local_cache_key {
if let Some(local_cache_key) = local_cache_key { local_cache_key == "404" || fs::metadata(&filepath).is_ok()
if local_cache_key == "404" {
true
} else {
fs::metadata(&filepath).is_ok()
}
} else {
false
}
} else { } else {
false false
}; };
if !local_file_ready { let strategy = ExponentialBackoff::from_millis(100).map(jitter).take(2);
let strategy = ExponentialBackoff::from_millis(100).map(jitter).take(2); let download_job = Retry::spawn(strategy, || {
let etag = Retry::spawn(strategy, || { download_file(registry, &url, &filepath, local_cache_key, !required)
download_file(registry, &url, &filepath, local_cache_key, !required) });
}) if let Ok(etag) = download_job.await {
.await?;
cache_info.set_local_cache_key(path, &etag).await; cache_info.set_local_cache_key(path, &etag).await;
} else if prefer_local_file && local_file_ready {
// Do nothing.
} else {
return Err(anyhow!("Failed to fetch url {}", url));
} }
cache_info.save(model_id)?; cache_info.save(model_id)?;