fix: if local file doens't exist, local_cache_key should be cleared (#501)
* fix: if local file doens't exist, local_cache_key should be cleared * fixrelease-0.2
parent
ce20bd6154
commit
6306bb3f01
|
|
@ -86,18 +86,17 @@ async fn download_model_file(
|
||||||
// Create url.
|
// Create url.
|
||||||
let url = registry.build_url(model_id, path);
|
let url = registry.build_url(model_id, path);
|
||||||
|
|
||||||
// Get cache key.
|
|
||||||
let local_cache_key = cache_info.local_cache_key(path);
|
|
||||||
|
|
||||||
// Create destination path.
|
// Create destination path.
|
||||||
let filepath = ModelDir::new(model_id).path_string(path);
|
let filepath = ModelDir::new(model_id).path_string(path);
|
||||||
|
|
||||||
// Cache hit.
|
// Get cache key.
|
||||||
let local_file_ready = if let Some(local_cache_key) = local_cache_key {
|
let local_cache_key = cache_info.local_cache_key(path);
|
||||||
local_cache_key == "404" || fs::metadata(&filepath).is_ok()
|
|
||||||
} else {
|
// Check local file ready.
|
||||||
false
|
let local_cache_key = local_cache_key
|
||||||
};
|
// local cache key is only valid if == 404 or local file exists.
|
||||||
|
// FIXME(meng): use sha256 to validate file is ready.
|
||||||
|
.filter(|&local_cache_key| local_cache_key == "404" || fs::metadata(&filepath).is_ok());
|
||||||
|
|
||||||
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 download_job = Retry::spawn(strategy, || {
|
||||||
|
|
@ -105,7 +104,7 @@ async fn download_model_file(
|
||||||
});
|
});
|
||||||
if let Ok(etag) = download_job.await {
|
if let Ok(etag) = download_job.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 {
|
} else if prefer_local_file && local_cache_key.is_some() {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
} else {
|
} else {
|
||||||
return Err(anyhow!("Failed to fetch url {}", url));
|
return Err(anyhow!("Failed to fetch url {}", url));
|
||||||
|
|
@ -137,11 +136,9 @@ async fn download_file(
|
||||||
}
|
}
|
||||||
|
|
||||||
let remote_cache_key = registry.build_cache_key(url).await?;
|
let remote_cache_key = registry.build_cache_key(url).await?;
|
||||||
if let Some(local_cache_key) = local_cache_key {
|
if local_cache_key == Some(remote_cache_key.as_str()) {
|
||||||
if local_cache_key == remote_cache_key {
|
|
||||||
return Ok(remote_cache_key);
|
return Ok(remote_cache_key);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let total_size = res
|
let total_size = res
|
||||||
.content_length()
|
.content_length()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue