mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
Fix directory not found exception when deleting stale repository (#136)
This commit is contained in:
parent
1cc9320a30
commit
d4e72566e2
2 changed files with 11 additions and 3 deletions
|
|
@ -15,6 +15,10 @@ vi.mock('glob', () => ({
|
||||||
glob: vi.fn().mockReturnValue(['fake_index.zoekt']),
|
glob: vi.fn().mockReturnValue(['fake_index.zoekt']),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
vi.mock('fs', () => ({
|
||||||
|
existsSync: vi.fn().mockReturnValue(true),
|
||||||
|
}));
|
||||||
|
|
||||||
const createMockContext = (rootPath: string = '/app') => {
|
const createMockContext = (rootPath: string = '/app') => {
|
||||||
return {
|
return {
|
||||||
configPath: path.join(rootPath, 'config.json'),
|
configPath: path.join(rootPath, 'config.json'),
|
||||||
|
|
@ -159,7 +163,7 @@ test('deleteStaleRepository can delete a git repository', async () => {
|
||||||
|
|
||||||
await deleteStaleRepository(repo, db, ctx);
|
await deleteStaleRepository(repo, db, ctx);
|
||||||
|
|
||||||
expect(db.data.repos['github.com/sourcebot-dev/sourcebot']).toBeUndefined();;
|
expect(db.data.repos['github.com/sourcebot-dev/sourcebot']).toBeUndefined();
|
||||||
expect(rm).toHaveBeenCalledWith(`${ctx.reposPath}/github.com/sourcebot-dev/sourcebot`, {
|
expect(rm).toHaveBeenCalledWith(`${ctx.reposPath}/github.com/sourcebot-dev/sourcebot`, {
|
||||||
recursive: true,
|
recursive: true,
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,10 @@ export const deleteStaleRepository = async (repo: Repository, db: Database, ctx:
|
||||||
logger.info(`Deleting stale repository ${repo.id}:`);
|
logger.info(`Deleting stale repository ${repo.id}:`);
|
||||||
|
|
||||||
// Delete the checked out git repository (if applicable)
|
// Delete the checked out git repository (if applicable)
|
||||||
if (repo.vcs === "git") {
|
if (repo.vcs === "git" && existsSync(repo.path)) {
|
||||||
logger.info(`\tDeleting git directory ${repo.path}...`);
|
logger.info(`\tDeleting git directory ${repo.path}...`);
|
||||||
await rm(repo.path, {
|
await rm(repo.path, {
|
||||||
recursive: true
|
recursive: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -116,6 +116,10 @@ export const deleteStaleRepository = async (repo: Repository, db: Database, ctx:
|
||||||
});
|
});
|
||||||
|
|
||||||
await Promise.all(indexFiles.map((file) => {
|
await Promise.all(indexFiles.map((file) => {
|
||||||
|
if (!existsSync(file)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
logger.info(`\tDeleting index file ${file}...`);
|
logger.info(`\tDeleting index file ${file}...`);
|
||||||
return rm(file);
|
return rm(file);
|
||||||
}));
|
}));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue