Skip to content

Commit

Permalink
Foreground cache scan when free space is low
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Jun 27, 2024
1 parent 6024d66 commit 4220c12
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/cache_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,20 @@ impl CacheManager {
let manager = new.clone();
let verify_cache = init_settings.verify_cache();
let static_range = init_settings.static_range();
if verify_cache && !force_background_scan {
// Force check cache
info!("Start force cache check");
let free = get_available_space(cache_dir.as_ref());
let low_disk = free.is_some_and(|x| x < SIZE_100MB);

if low_disk || (verify_cache && !force_background_scan) {
// Low space or force cache check
if low_disk {
warn!("Disk space is low than 100MiB: available={}MiB", free.unwrap() / 1024 / 1024);
}

if verify_cache {
info!("Start force cache check");
} else {
info!("Start foreground cache scan due to low disk space");
}
new.scan_cache(static_range, 16, verify_cache).await?;
CacheManager::start_background_task(manager);
} else {
Expand Down

2 comments on commit 4220c12

@lukasva77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've switched to your version of the client but on startup HDD makes noises for two hours I'm guessing this commit is the feature responsible needs an option to switch it off like in the original client

--skip_free_space_check

@james58899
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lukasva77
Unlike the official version, the cache is scanned on every launch to accurately calculate the size.
Since cache scanning is done in the background and the client is usually not restarted very often, this is usually not a problem for most people.
If this is a problem for you please open an issue and I may implement cache state storage in the future.

Please sign in to comment.