mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:40:44 +00:00
Refactor file access to use fs-safe primitives (#78255)
* refactor: use fs-safe primitives across file access * fix: preserve invalid managed npm manifests * fix: keep fs seams for startup metadata
This commit is contained in:
committed by
GitHub
parent
0d73f174a9
commit
b85b1c68d1
@@ -1,7 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import { createRequire } from "node:module";
|
||||
import type { ThemeRegistrationResolved } from "@pierre/diffs";
|
||||
import { RegisteredCustomThemes, ResolvedThemes, ResolvingThemes } from "@pierre/diffs";
|
||||
import { readJsonFileWithFallback } from "openclaw/plugin-sdk/json-store";
|
||||
|
||||
type PierreThemeName = "pierre-dark" | "pierre-light";
|
||||
const themeRequire = createRequire(import.meta.url);
|
||||
@@ -20,8 +20,9 @@ function createThemeLoader(
|
||||
return cachedTheme;
|
||||
}
|
||||
const themePath = themeRequire.resolve(themeSpecifier);
|
||||
const { value: theme } = await readJsonFileWithFallback<Record<string, unknown>>(themePath, {});
|
||||
cachedTheme = {
|
||||
...(JSON.parse(await fs.readFile(themePath, "utf8")) as Record<string, unknown>),
|
||||
...theme,
|
||||
name: themeName,
|
||||
} as ThemeRegistrationResolved;
|
||||
return cachedTheme;
|
||||
|
||||
@@ -174,13 +174,13 @@ export class DiffArtifactStore {
|
||||
}
|
||||
|
||||
async cleanupExpired(): Promise<void> {
|
||||
await this.ensureRoot();
|
||||
const entries = await fs.readdir(this.rootDir, { withFileTypes: true }).catch(() => []);
|
||||
const root = await this.artifactRoot();
|
||||
const entries = await root.list("", { withFileTypes: true }).catch(() => []);
|
||||
const now = Date.now();
|
||||
|
||||
await Promise.all(
|
||||
entries
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.filter((entry) => entry.isDirectory)
|
||||
.map(async (entry) => {
|
||||
const id = entry.name;
|
||||
const meta = await this.readMeta(id);
|
||||
@@ -199,12 +199,7 @@ export class DiffArtifactStore {
|
||||
return;
|
||||
}
|
||||
|
||||
const artifactPath = this.artifactDir(id);
|
||||
const stat = await fs.stat(artifactPath).catch(() => null);
|
||||
if (!stat) {
|
||||
return;
|
||||
}
|
||||
if (now - stat.mtimeMs > SWEEP_FALLBACK_AGE_MS) {
|
||||
if (now - entry.mtimeMs > SWEEP_FALLBACK_AGE_MS) {
|
||||
await this.deleteArtifact(id);
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user