Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(storage): skip non-directory entries when scanning browser partitions

yu.xiad785b89d8743
diff --git a/apps/desktop/electron/main/storage/files.ts b/apps/desktop/electron/main/storage/files.ts
index 78613a902..b12daafa3 100644
--- a/apps/desktop/electron/main/storage/files.ts
+++ b/apps/desktop/electron/main/storage/files.ts
@@ -28,7 +28,7 @@ export function contains(parent: string, child: string): boolean {
}
async function optionalStat(path: string) {
try { return await lstat(path); }
- catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT") return null; throw error; }
+ catch (error) { if ((error as NodeJS.ErrnoException).code === "ENOENT" || (error as NodeJS.ErrnoException).code === "ENOTDIR") return null; throw error; }
}
export async function validateTarget(path: string, source: StorageRoots, anchor: string, retryId?: string): Promise<string> {
@@ -202,7 +202,11 @@ async function safeCachePaths(roots: StorageRoots): Promise<string[]> {
candidates.push(...BROWSER_CACHE_PATHS.map((path) => join(roots.browser, path)));
const partitions = join(roots.browser, "Partitions");
if ((await optionalStat(partitions))?.isDirectory() && !(await lstat(partitions)).isSymbolicLink()) {
- for (const name of await readdir(partitions)) candidates.push(...BROWSER_CACHE_PATHS.map((path) => join(partitions, name, path)));
+ // Only real partition directories hold caches; Finder-style files such as
+ // .DS_Store must not become candidates whose <name>/Cache path is not statable.
+ for (const entry of await readdir(partitions, { withFileTypes: true })) {
+ if (entry.isDirectory()) candidates.push(...BROWSER_CACHE_PATHS.map((path) => join(partitions, entry.name, path)));
+ }
}
const result: string[] = [];
for (const candidate of candidates) {
diff --git a/apps/desktop/test/storage-maintenance.test.mjs b/apps/desktop/test/storage-maintenance.test.mjs
index 26e26b5c8..8fdab182a 100644
--- a/apps/desktop/test/storage-maintenance.test.mjs
+++ b/apps/desktop/test/storage-maintenance.test.mjs
@@ -381,6 +381,18 @@ test("cache cleanup removes disposable caches while preserving sessions, secrets
assert.equal(await storage.cacheSize(value.roots), 0);
});
+test("cache size ignores non-directory entries inside the partitions directory", { timeout: 60_000 }, async (t) => {
+ const value = await fixture(t);
+ await put(join(value.roots.browser, "Partitions/plugin-1/Cache/response"), "1234");
+ // Finder leaves .DS_Store files next to the partitions; treating one as a
+ // partition makes cacheSize fail with ENOTDIR on `<name>/Cache` instead of
+ // ignoring it, which surfaces as the settings storage-path error.
+ await put(join(value.roots.browser, "Partitions/.DS_Store"), "junk");
+ assert.equal(await storage.cacheSize(value.roots), 4);
+ await storage.clearCaches(value.roots);
+ assert.equal(await readFile(join(value.roots.browser, "Partitions/.DS_Store"), "utf8"), "junk");
+});
+
test("cache cleanup does not follow plugin, partition or leaf cache links outside storage", { timeout: 60_000 }, async (t) => {
const value = await fixture(t); const external = join(value.root, "external");
await put(join(external, "cache/download/pkg"), "external");