3
0
Fork 0
mirror of https://github.com/Swatinem/rust-cache synced 2026-03-04 07:40:24 +00:00

serialization bugs

This commit is contained in:
Jonathan Kelley 2025-01-28 23:37:52 -08:00
parent 5bbbdb9115
commit 829dfd6b08
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
4 changed files with 23 additions and 12 deletions

View file

@ -8,13 +8,18 @@ import fs from "fs";
import path from "path";
export type MtimeData = {
roots: Array<string>,
times: Map<string, number>
roots: string[],
times: {
[key: string]: number
}
};
export async function saveMtimes(targetDirs: string[]): Promise<MtimeData> {
let times = new Map<string, number>();
let stack = new Array<string>();
let data: MtimeData = {
roots: [],
times: {},
};
let stack: string[] = [];
// Collect all the incremental files
for (const dir of targetDirs) {
@ -28,7 +33,7 @@ export async function saveMtimes(targetDirs: string[]): Promise<MtimeData> {
}
// Save the stack as the roots - we cache these directly
let roots = stack.slice();
data.roots = stack.slice();
while (stack.length > 0) {
const dirName = stack.pop()!;
@ -40,10 +45,10 @@ export async function saveMtimes(targetDirs: string[]): Promise<MtimeData> {
} else {
const fileName = path.join(dirName, dirent.name);
const { mtime } = await fs.promises.stat(fileName);
times.set(fileName, mtime.getTime());
data.times[fileName] = mtime.getTime();
}
}
}
return { roots, times: times };
return data;
}