Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Commit

Permalink
Merge 6ea4099 into 545e286
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-palmer committed Jan 15, 2019
2 parents 545e286 + 6ea4099 commit 309bc23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/cache/cache_fs.js
Expand Up @@ -226,11 +226,9 @@ class CacheFS extends CacheBase {
spinnerMessage = 'Gathering files to delete to satisfy Max cache size';

await helpers.readDir(this._cachePath, (item) => {
if (item.stats.isDirectory()) return next();

if (item.stats.atime < minFileAccessTime) {
// already expired items are handled in the previous pass
return next();
// already expired items are handled in the previous pass (only relevant for dry-run)
return;
}

item = {path: item.path, stats: pick(item.stats, ['atime', 'size'])};
Expand Down
11 changes: 11 additions & 0 deletions test/cache_fs.js
Expand Up @@ -122,16 +122,27 @@ describe("Cache: FS", () => {
const file1 = await addFileToCache(moment().toDate());
const file2 = await addFileToCache(moment().subtract(1, 'days').toDate());
const file3 = await addFileToCache(moment().subtract(5, 'days').toDate());
const file4 = await addFileToCache(moment().subtract(31, 'days').toDate());

assert(await fs.pathExists(file1.path));
assert(await fs.pathExists(file2.path));
assert(await fs.pathExists(file3.path));
assert(await fs.pathExists(file4.path));

// Execute dry-run path first for complete coverage
await cache.cleanup(true);

assert(await fs.pathExists(file1.path));
assert(await fs.pathExists(file2.path));
assert(await fs.pathExists(file3.path));
assert(await fs.pathExists(file4.path));

await cache.cleanup(false);

assert(await fs.pathExists(file1.path));
assert(await fs.pathExists(file2.path));
assert(!await fs.pathExists(file3.path));
assert(!await fs.pathExists(file4.path));

opts.cleanupOptions.maxCacheSize = MIN_FILE_SIZE + 1;
cache._options = opts;
Expand Down

0 comments on commit 309bc23

Please sign in to comment.