mirror of
https://github.com/Swatinem/rust-cache
synced 2026-03-04 07:40:24 +00:00
cache the roots not the files
This commit is contained in:
parent
01addf7215
commit
6095cc4363
5 changed files with 60 additions and 24 deletions
|
|
@ -7,9 +7,28 @@ import path from "path";
|
|||
// import { exists } from "./utils";
|
||||
// import { Packages } from "./workspace";
|
||||
|
||||
export async function saveMtimes(targetDirs: string[]): Promise<Map<string, number>> {
|
||||
let cache = new Map<string, number>();
|
||||
let stack = targetDirs.slice();
|
||||
export type MtimeData = {
|
||||
roots: Array<string>,
|
||||
times: Map<string, number>
|
||||
};
|
||||
|
||||
export async function saveMtimes(targetDirs: string[]): Promise<MtimeData> {
|
||||
let times = new Map<string, number>();
|
||||
let stack = new Array<string>();
|
||||
|
||||
// Collect all the incremental files
|
||||
for (const dir of targetDirs) {
|
||||
for (const maybeProfile of await fs.promises.readdir(dir)) {
|
||||
const profileDir = path.join(dir, maybeProfile);
|
||||
const incrementalDir = path.join(profileDir, "incremental");
|
||||
if (fs.existsSync(incrementalDir)) {
|
||||
stack.push(incrementalDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save the stack as the roots - we cache these directly
|
||||
let roots = stack.slice();
|
||||
|
||||
while (stack.length > 0) {
|
||||
const dirName = stack.pop()!;
|
||||
|
|
@ -21,10 +40,10 @@ export async function saveMtimes(targetDirs: string[]): Promise<Map<string, numb
|
|||
} else {
|
||||
const fileName = path.join(dirName, dirent.name);
|
||||
const { mtime } = await fs.promises.stat(fileName);
|
||||
cache.set(fileName, mtime.getTime());
|
||||
times.set(fileName, mtime.getTime());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cache;
|
||||
return { roots, times: times };
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue