Skip to content

Commit

Permalink
feat: panic for programmer error, more diagnostics, remove duplicated…
Browse files Browse the repository at this point in the history
… map lookup (#126)
  • Loading branch information
KSXGitHub authored Sep 20, 2023
1 parent 94f2848 commit 59a553e
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions crates/tarball/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,23 @@ pub async fn download_tarball_to_store(
}
CacheValue::InProgress(notify) => Arc::clone(notify),
};

tracing::info!(target: "pacquet::download", ?package_url, "Wait for cache");
notify.notified().await;
if let Some(cached) = cache.get(package_url) {
if let CacheValue::Available(cas_paths) = &*cached.read().await {
return Ok(Arc::clone(cas_paths));
}
if let CacheValue::Available(cas_paths) = &*cache_lock.read().await {
return Ok(Arc::clone(cas_paths));
}
Err(TarballError::Io(std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to get or compute tarball data",
)))
unreachable!("Failed to get or compute tarball data for {package_url:?}");
} else {
let notify = Arc::new(Notify::new());
let cache_lock = notify
.pipe_ref(Arc::clone)
.pipe(CacheValue::InProgress)
.pipe(RwLock::new)
.pipe(Arc::new);
cache.insert(package_url.to_string(), Arc::clone(&cache_lock));
if cache.insert(package_url.to_string(), Arc::clone(&cache_lock)).is_some() {
tracing::warn!(target: "pacquet::download", ?package_url, "Race condition detected when writing to cache");
}
let cas_paths = download_tarball_to_store_uncached(
package_url,
http_client,
Expand Down

0 comments on commit 59a553e

Please sign in to comment.