Skip to content

Commit d4e7256

Browse files
Fix directory not found exception when deleting stale repository (#136)
1 parent 1cc9320 commit d4e7256

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

packages/backend/src/main.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ vi.mock('glob', () => ({
1515
glob: vi.fn().mockReturnValue(['fake_index.zoekt']),
1616
}));
1717

18+
vi.mock('fs', () => ({
19+
existsSync: vi.fn().mockReturnValue(true),
20+
}));
21+
1822
const createMockContext = (rootPath: string = '/app') => {
1923
return {
2024
configPath: path.join(rootPath, 'config.json'),
@@ -159,7 +163,7 @@ test('deleteStaleRepository can delete a git repository', async () => {
159163

160164
await deleteStaleRepository(repo, db, ctx);
161165

162-
expect(db.data.repos['github.com/sourcebot-dev/sourcebot']).toBeUndefined();;
166+
expect(db.data.repos['github.com/sourcebot-dev/sourcebot']).toBeUndefined();
163167
expect(rm).toHaveBeenCalledWith(`${ctx.reposPath}/github.com/sourcebot-dev/sourcebot`, {
164168
recursive: true,
165169
});

packages/backend/src/main.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ export const deleteStaleRepository = async (repo: Repository, db: Database, ctx:
7373
logger.info(`Deleting stale repository ${repo.id}:`);
7474

7575
// Delete the checked out git repository (if applicable)
76-
if (repo.vcs === "git") {
76+
if (repo.vcs === "git" && existsSync(repo.path)) {
7777
logger.info(`\tDeleting git directory ${repo.path}...`);
7878
await rm(repo.path, {
79-
recursive: true
79+
recursive: true,
8080
});
8181
}
8282

@@ -116,6 +116,10 @@ export const deleteStaleRepository = async (repo: Repository, db: Database, ctx:
116116
});
117117

118118
await Promise.all(indexFiles.map((file) => {
119+
if (!existsSync(file)) {
120+
return;
121+
}
122+
119123
logger.info(`\tDeleting index file ${file}...`);
120124
return rm(file);
121125
}));

0 commit comments

Comments
 (0)