MCPcopy Index your code
hub / github.com/coder/mux / copyPlanFile

Function copyPlanFile

src/node/utils/runtime/helpers.ts:238–266  ·  view source on GitHub ↗
(
  runtime: Runtime,
  sourceWorkspaceName: string,
  sourceWorkspaceId: string,
  targetWorkspaceName: string,
  projectName: string
)

Source from the content-addressed store, hash-verified

236 * Silently succeeds if source file doesn't exist at either location.
237 */
238export async function copyPlanFile(
239 runtime: Runtime,
240 sourceWorkspaceName: string,
241 sourceWorkspaceId: string,
242 targetWorkspaceName: string,
243 projectName: string
244): Promise<void> {
245 const muxHome = runtime.getMuxHome();
246 const sourcePath = getPlanFilePath(sourceWorkspaceName, projectName, muxHome);
247 // Legacy paths only used for non-Docker runtimes
248 const legacySourcePath = getLegacyPlanFilePath(sourceWorkspaceId);
249 const targetPath = getPlanFilePath(targetWorkspaceName, projectName, muxHome);
250
251 // Prefer the new layout, but fall back to the legacy layout.
252 //
253 // Note: we intentionally use runtime file I/O instead of `cp` because:
254 // 1) bash doesn't expand ~ inside quotes
255 // 2) the target per-project plan directory may not exist yet
256 // 3) runtime.writeFile() already handles directory creation + tilde expansion
257 for (const candidatePath of [sourcePath, legacySourcePath]) {
258 try {
259 const content = await readFileString(runtime, candidatePath);
260 await writeFileString(runtime, targetPath, content);
261 return;
262 } catch {
263 // Try next candidate
264 }
265 }
266}
267
268/**
269 * Copy a plan file across runtimes (e.g., during fork where source/target may be

Callers

nothing calls this directly

Calls 5

getPlanFilePathFunction · 0.90
getLegacyPlanFilePathFunction · 0.90
readFileStringFunction · 0.85
writeFileStringFunction · 0.85
getMuxHomeMethod · 0.65

Tested by

no test coverage detected