MCPcopy
hub / github.com/Fission-AI/OpenSpec / removeStore

Function removeStore

src/core/store/operations.ts:918–977  ·  view source on GitHub ↗
(
  target: PreparedStoreCleanup
)

Source from the content-addressed store, hash-verified

916}
917
918export async function removeStore(
919 target: PreparedStoreCleanup
920): Promise<StoreCleanupResult> {
921 const id = validateStoreId(target.id);
922 const diagnostics: StoreDiagnostic[] = [];
923 let deleted = false;
924
925 // Order matters: the registry entry goes first, the files second. A
926 // failed file deletion leaves recoverable orphan files; the reverse
927 // order would leave a phantom registration pointing at nothing.
928 let rootMissing = false;
929 const removed = await unregisterStoreRegistration({
930 id,
931 expectedBackend: target.backend,
932 globalDataDir: target.globalDataDir,
933 beforeCommit: async (entry) => {
934 const safeTarget = await assertSafeToDeleteStoreRoot(entry.storeRoot, id);
935 rootMissing = !safeTarget.exists;
936 },
937 });
938
939 if (rootMissing) {
940 diagnostics.push(makeStoreDiagnostic(
941 'warning',
942 'store_root_missing',
943 'Store files were already missing.',
944 {
945 target: 'store.root',
946 }
947 ));
948 } else {
949 try {
950 await fs.rm(removed.storeRoot, { recursive: true, force: true });
951 deleted = true;
952 } catch (error) {
953 diagnostics.push(makeStoreDiagnostic(
954 'warning',
955 'store_files_left_on_disk',
956 `The registration was removed, but deleting ${removed.storeRoot} failed (${(error as Error).message}).`,
957 {
958 target: 'store.root',
959 fix: `Delete the folder manually: ${removed.storeRoot}`,
960 }
961 ));
962 }
963 }
964
965 return {
966 store: cleanupStoreOutput(removed.id, removed.storeRoot),
967 registryCommit: {
968 path: getStoreRegistryPath({ globalDataDir: target.globalDataDir }),
969 removed: true,
970 },
971 files: {
972 deleted,
973 ...(deleted ? { deletedPath: removed.storeRoot } : {}),
974 },
975 diagnostics,

Callers 2

registry.test.tsFile · 0.85
removeMethod · 0.85

Calls 6

validateStoreIdFunction · 0.85
makeStoreDiagnosticFunction · 0.85
cleanupStoreOutputFunction · 0.85
getStoreRegistryPathFunction · 0.85

Tested by

no test coverage detected