Skip to content

Commit cb80bb0

Browse files
DownDfornwall
authored andcommitted
Fix issue with clear-cache
1 parent 241239f commit cb80bb0

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/main.rs

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -239,26 +239,29 @@ fn clean_cache(max_age: u128) -> MainResult<()> {
239239
info!("cutoff: {:>20?} ms", cutoff);
240240

241241
let cache_dir = platform::generated_projects_cache_path();
242-
for child in fs::read_dir(cache_dir)? {
243-
let child = child?;
244-
let path = child.path();
245-
if path.is_file() {
246-
continue;
247-
}
248-
249-
info!("checking: {:?}", path);
250-
251-
let remove_dir = || {
252-
let meta_mtime = platform::dir_last_modified(&child);
253-
info!("meta_mtime: {:>20?} ms", meta_mtime);
254-
255-
meta_mtime <= cutoff
256-
};
257242

258-
if remove_dir() {
259-
info!("removing {:?}", path);
260-
if let Err(err) = fs::remove_dir_all(&path) {
261-
error!("failed to remove {:?} from cache: {}", path, err);
243+
if cache_dir.exists(){
244+
for child in fs::read_dir(cache_dir)? {
245+
let child = child?;
246+
let path = child.path();
247+
if path.is_file() {
248+
continue;
249+
}
250+
251+
info!("checking: {:?}", path);
252+
253+
let remove_dir = || {
254+
let meta_mtime = platform::dir_last_modified(&child);
255+
info!("meta_mtime: {:>20?} ms", meta_mtime);
256+
257+
meta_mtime <= cutoff
258+
};
259+
260+
if remove_dir() {
261+
info!("removing {:?}", path);
262+
if let Err(err) = fs::remove_dir_all(&path) {
263+
error!("failed to remove {:?} from cache: {}", path, err);
264+
}
262265
}
263266
}
264267
}

0 commit comments

Comments
 (0)