MCPcopy
hub / github.com/coder/mux / hasNonEmptyPlanFile

Function hasNonEmptyPlanFile

src/node/utils/runtime/helpers.ts:171–199  ·  view source on GitHub ↗
(
  runtime: Runtime,
  workspaceName: string,
  projectName: string,
  workspaceId: string
)

Source from the content-addressed store, hash-verified

169 * Checks both the canonical (per-project) path and the legacy (by workspaceId) path.
170 */
171export async function hasNonEmptyPlanFile(
172 runtime: Runtime,
173 workspaceName: string,
174 projectName: string,
175 workspaceId: string
176): Promise<boolean> {
177 // Defensive: missing identifiers means we cannot safely resolve plan paths.
178 if (!workspaceName || !projectName || !workspaceId) {
179 return false;
180 }
181
182 const muxHome = runtime.getMuxHome();
183 const planPath = getPlanFilePath(workspaceName, projectName, muxHome);
184 // Legacy paths only used for non-Docker runtimes.
185 const legacyPath = getLegacyPlanFilePath(workspaceId);
186
187 for (const candidatePath of [planPath, legacyPath]) {
188 try {
189 const stat = await runtime.stat(candidatePath);
190 if (!stat.isDirectory && stat.size > 0) {
191 return true;
192 }
193 } catch {
194 // Try next candidate.
195 }
196 }
197
198 return false;
199}
200
201/**
202 * Move a plan file from one workspace name to another (e.g., during rename).

Callers

nothing calls this directly

Calls 4

getPlanFilePathFunction · 0.90
getLegacyPlanFilePathFunction · 0.90
getMuxHomeMethod · 0.65
statMethod · 0.65

Tested by

no test coverage detected