Skip to content

Commit

Permalink
fix cache dir cleanup for free disk space, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Jun 18, 2023
1 parent ce370b1 commit a11b75b
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/docbuilder/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ static LAST_ACCESSED_FILE_NAME: &str = "docsrs_last_accessed";
/// filesystem where the given `path` lives on.
/// Return value is between 0 and 1.
fn free_disk_space_ratio<P: AsRef<Path>>(path: P) -> Result<f32> {
let sys = System::new_with_specifics(RefreshKind::new().with_disks());
let sys = System::new_with_specifics(RefreshKind::new().with_disks().with_disks_list());

let disk_by_mount_point: HashMap<_, _> =
sys.disks().iter().map(|d| (d.mount_point(), d)).collect();
Expand Down Expand Up @@ -326,4 +326,24 @@ mod tests {
assert_eq!(fs::read_dir(cache_path).unwrap().count(), 0);
assert!(cache_path.exists());
}

#[test]
fn test_dont_clean_disk_space() {
let cache_dir = tempfile::tempdir().unwrap();
let cache_path = cache_dir.path();
let cache = ArtifactCache::new(cache_path.to_owned()).unwrap();

// put something into the cache
for key in &["1", "2", "3"] {
cache.touch(key).unwrap();
}

assert_eq!(fs::read_dir(cache_path).unwrap().count(), 3);

// will clean nothing
cache.clear_disk_space(0.0).unwrap();

assert_eq!(fs::read_dir(cache_path).unwrap().count(), 3);
assert!(cache_path.exists());
}
}

0 comments on commit a11b75b

Please sign in to comment.