MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / rollbackArtifact

Function rollbackArtifact

src/artifacts/store.ts:241–252  ·  view source on GitHub ↗
(cwd: string, id: string, toVersion: number, write: WriteFn, now = new Date().toISOString())

Source from the content-addressed store, hash-verified

239
240/** Roll the "current" pointer back to an earlier (existing) version — no new file. */
241export async function rollbackArtifact(cwd: string, id: string, toVersion: number, write: WriteFn, now = new Date().toISOString()): Promise<ArtifactManifest> {
242 // Lock so a concurrent updateArtifact can't slip a new version in between our
243 // read and write (which would drop that version when we save the manifest).
244 return withLock(manifestLockPath(cwd, id), async () => {
245 const manifest = await readManifest(cwd, id);
246 if (!manifest) throw new Error(`Artifact "${id}" not found.`);
247 if (!manifest.versions.some(v => v.v === toVersion)) throw new Error(`Artifact "${id}" has no version ${toVersion}.`);
248 const updated: ArtifactManifest = { ...manifest, current: toVersion, updatedAt: now };
249 await writeFileAtomic(manifestPath(cwd, id), JSON.stringify(updated, null, 2));
250 return updated;
251 });
252}

Callers 3

mainFunction · 0.90
executeMethod · 0.85

Calls 5

withLockFunction · 0.85
manifestLockPathFunction · 0.85
writeFileAtomicFunction · 0.85
readManifestFunction · 0.70
manifestPathFunction · 0.70

Tested by 1

mainFunction · 0.72