Skip to content

Commit

Permalink
add more warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aawsome committed Apr 27, 2024
1 parent ef0c568 commit 6495674
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 17 additions & 7 deletions crates/core/src/backend/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ impl ReadBackend for CachedBackend {
let list = self.be.list_with_size(tpe)?;

if tpe.is_cacheable() {
self.cache.remove_not_in_list(tpe, &list)?;
if let Err(err) = self.cache.remove_not_in_list(tpe, &list) {
warn!("Error in cache backend removing files {tpe:?}: {err}");
}
}

Ok(list)
Expand All @@ -95,11 +97,13 @@ impl ReadBackend for CachedBackend {
match self.cache.read_full(tpe, id) {
Ok(Some(data)) => return Ok(data),
Ok(None) => {}
Err(err) => warn!("Error in cache backend: {err}"),
Err(err) => warn!("Error in cache backend reading {tpe:?},{id}: {err}"),
}
let res = self.be.read_full(tpe, id);
if let Ok(data) = &res {
_ = self.cache.write_bytes(tpe, id, data);
if let Err(err) = self.cache.write_bytes(tpe, id, data) {
warn!("Error in cache backend writing {tpe:?},{id}: {err}");
}
}
res
} else {
Expand Down Expand Up @@ -138,13 +142,15 @@ impl ReadBackend for CachedBackend {
match self.cache.read_partial(tpe, id, offset, length) {
Ok(Some(data)) => return Ok(data),
Ok(None) => {}
Err(err) => warn!("Error in cache backend: {err}"),
Err(err) => warn!("Error in cache backend reading {tpe:?},{id}: {err}"),
};
// read full file, save to cache and return partial content
match self.be.read_full(tpe, id) {
Ok(data) => {
let range = offset as usize..(offset + length) as usize;
_ = self.cache.write_bytes(tpe, id, &data);
if let Err(err) = self.cache.write_bytes(tpe, id, &data) {
warn!("Error in cache backend writing {tpe:?},{id}: {err}");
}
Ok(Bytes::copy_from_slice(&data.slice(range)))
}
error => error,
Expand Down Expand Up @@ -180,7 +186,9 @@ impl WriteBackend for CachedBackend {
/// * `buf` - The data to write.
fn write_bytes(&self, tpe: FileType, id: &Id, cacheable: bool, buf: Bytes) -> Result<()> {
if cacheable || tpe.is_cacheable() {
_ = self.cache.write_bytes(tpe, id, &buf);
if let Err(err) = self.cache.write_bytes(tpe, id, &buf) {
warn!("Error in cache backend writing {tpe:?},{id}: {err}");
}
}
self.be.write_bytes(tpe, id, cacheable, buf)
}
Expand All @@ -195,7 +203,9 @@ impl WriteBackend for CachedBackend {
/// * `id` - The id of the file.
fn remove(&self, tpe: FileType, id: &Id, cacheable: bool) -> Result<()> {
if cacheable || tpe.is_cacheable() {
_ = self.cache.remove(tpe, id);
if let Err(err) = self.cache.remove(tpe, id) {
warn!("Error in cache backend removing {tpe:?},{id}: {err}");
}
}
self.be.remove(tpe, id, cacheable)
}
Expand Down
5 changes: 4 additions & 1 deletion crates/core/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ impl CheckOptions {

if let Some(cache) = &cache {
let p = pb.progress_spinner("cleaning up packs from cache...");
cache.remove_not_in_list(FileType::Pack, index_collector.tree_packs())?;
if let Err(err) = cache.remove_not_in_list(FileType::Pack, index_collector.tree_packs())
{
warn!("Error in cache backend removing pack files: {err}");
}
p.finish();

if !self.trust_cache {
Expand Down

0 comments on commit 6495674

Please sign in to comment.