mirror of
https://github.com/awalsh128/cache-apt-pkgs-action.git
synced 2026-11-14 05:46:50 +00:00
Manifest.from built every entry with an empty file list and buildFileList was never called, so tar.create was handed no paths. node-tar throws "no paths specified to add to archive" for that, so every cache miss failed before saving. The runner now builds each manifest entry from buildFileList and passes the manifest to archiveAndSave. Packages with no files (e.g. metapackages) are skipped on archive and on restore since tar can't create an empty archive. Manifest.from is removed. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import fs from "node:fs";
|
|
import { CacheKey } from "./cache.js";
|
|
import { packageNameFromJSON, PackageName } from "ts-apt";
|
|
|
|
export class ManifestEntry {
|
|
readonly packageName: PackageName;
|
|
readonly filepaths: string[];
|
|
|
|
constructor(packageName: PackageName, filepaths: string[] = []) {
|
|
this.packageName = packageName;
|
|
this.filepaths = [...filepaths].sort((a, b) => a.localeCompare(b));
|
|
}
|
|
|
|
static fromJSON(json: any): ManifestEntry {
|
|
return new ManifestEntry(
|
|
packageNameFromJSON(json.packageName),
|
|
json.filepaths as string[],
|
|
);
|
|
}
|
|
}
|
|
|
|
export class Manifest {
|
|
constructor(
|
|
public readonly created: Date,
|
|
public readonly entries: ManifestEntry[],
|
|
public readonly cacheKey: CacheKey,
|
|
) {}
|
|
|
|
// Static factory method
|
|
static fromJSON(json: any): Manifest {
|
|
return new Manifest(
|
|
new Date(json.created),
|
|
json.entries.map(
|
|
(e: any) =>
|
|
new ManifestEntry(
|
|
packageNameFromJSON(e.packageName),
|
|
e.filepaths as string[],
|
|
),
|
|
),
|
|
CacheKey.fromJSON(json.cacheKey),
|
|
);
|
|
}
|
|
|
|
static async readFromFile(filePath: string): Promise<Manifest> {
|
|
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
return Manifest.fromJSON(JSON.parse(content));
|
|
}
|
|
|
|
async writeToFile(filePath: string): Promise<void> {
|
|
await fs.promises.writeFile(
|
|
filePath,
|
|
JSON.stringify(this, null, 2),
|
|
"utf8",
|
|
);
|
|
}
|
|
}
|