MCPcopy Create free account
hub / github.com/sourcebot-dev/sourcebot / cleanupTempShards

Function cleanupTempShards

packages/backend/src/zoekt.ts:64–86  ·  view source on GitHub ↗
(repo: Repo)

Source from the content-addressed store, hash-verified

62 * @param repo - The repository whose temp shards should be cleaned up
63 */
64export const cleanupTempShards = async (repo: Repo) => {
65 const shardPrefix = getShardPrefix(repo.orgId, repo.id);
66
67 try {
68 const files = await readdir(INDEX_CACHE_DIR);
69 const tempFiles = files.filter(file =>
70 file.startsWith(shardPrefix) && file.includes('.tmp')
71 );
72
73 for (const file of tempFiles) {
74 const filePath = `${INDEX_CACHE_DIR}/${file}`;
75 logger.debug(`Cleaning up temp shard file: ${filePath}`);
76 await rm(filePath, { force: true });
77 }
78
79 if (tempFiles.length > 0) {
80 logger.debug(`Cleaned up ${tempFiles.length} temp shard file(s) for repo ${repo.id}`);
81 }
82 } catch (error) {
83 // Log but don't throw - cleanup is best effort
84 logger.warn(`Failed to cleanup temp shards for repo ${repo.id}:`, error);
85 }
86}

Callers 1

indexRepositoryMethod · 0.85

Calls 1

getShardPrefixFunction · 0.85

Tested by

no test coverage detected