Skip to content

Commit 52e8788

Browse files
fix(server): storage cleanup skips stale worktree paths under a regular file (pingdotgg#26594)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e0379fb commit 52e8788

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

‎apps/server/src/storageCleanup.test.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,21 @@ describe("storage cleanup reports and local file policies", () => {
21072107
}),
21082108
),
21092109
);
2110+
it.live("skips a stored worktree path whose parent is a regular file", () =>
2111+
runCleanupTest(
2112+
Effect.gen(function* () {
2113+
const fixture = yield* cleanupFixture();
2114+
const legacyRoot = `${fixture.config.worktreesDir}/legacy-root`;
2115+
yield* fixture.fs.writeFileString(legacyRoot, "");
2116+
fixture.setThreads([
2117+
shell({ branch: "feature", worktreePath: `${legacyRoot}/stored-workspace` }),
2118+
]);
2119+
const report = yield* fixture.service.runNow;
2120+
expect(report.entries).toEqual([]);
2121+
expect(report.counts).toEqual({ removed: 0, kept: 0, failed: 0 });
2122+
}),
2123+
),
2124+
);
21102125
it.live.each(["before-check", "while-measuring"] as const)(
21112126
"keeps a worktree protected by a missing project root (%s)",
21122127
(timing) =>

‎apps/server/src/storageCleanup.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,17 @@ const make = Effect.gen(function* () {
925925
return reason;
926926
};
927927
yield* Effect.gen(function* () {
928-
if (!(yield* fs.exists(worktreePath))) return;
928+
const exists = yield* fs.exists(worktreePath).pipe(
929+
// A stored path under a regular file cannot exist, but access() fails with ENOTDIR.
930+
Effect.catchIf(
931+
(error) =>
932+
error.cause instanceof Error &&
933+
"code" in error.cause &&
934+
error.cause.code === "ENOTDIR",
935+
() => Effect.succeed(false),
936+
),
937+
);
938+
if (!exists) return;
929939
if (deleted && !settings.worktreeOnDelete) return keep("no rules apply");
930940
if (members.length > 1 && worktreeOwner(members) === undefined)
931941
return keep(`shared by ${members.length} threads`);

0 commit comments

Comments
 (0)