mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Improve workspace delete handler
This commit is contained in:
@@ -77,13 +77,16 @@ class DatabaseService {
|
||||
return this.workspaceDatabases;
|
||||
}
|
||||
|
||||
public async deleteWorkspaceDatabase(userId: string): Promise<void> {
|
||||
public async removeWorkspaceDatabase(userId: string): Promise<void> {
|
||||
this.debug(`Deleting workspace database for user: ${userId}`);
|
||||
await this.waitForInit();
|
||||
|
||||
if (this.workspaceDatabases.has(userId)) {
|
||||
this.workspaceDatabases.delete(userId);
|
||||
const workspaceDatabase = this.workspaceDatabases.get(userId);
|
||||
if (workspaceDatabase) {
|
||||
workspaceDatabase.destroy();
|
||||
}
|
||||
|
||||
this.workspaceDatabases.delete(userId);
|
||||
}
|
||||
|
||||
private async waitForInit(): Promise<void> {
|
||||
|
||||
@@ -340,12 +340,34 @@ class AccountService {
|
||||
this.debug(`Deleted workspace ${userId}`);
|
||||
}
|
||||
|
||||
await databaseService.deleteWorkspaceDatabase(userId);
|
||||
await databaseService.removeWorkspaceDatabase(userId);
|
||||
const workspaceDir = getWorkspaceDirectoryPath(userId);
|
||||
if (fs.existsSync(workspaceDir)) {
|
||||
fs.rmSync(workspaceDir, { recursive: true });
|
||||
|
||||
let deleted = false;
|
||||
for (let attempt = 1; attempt <= 5; attempt++) {
|
||||
try {
|
||||
if (fs.existsSync(workspaceDir)) {
|
||||
fs.rmSync(workspaceDir, { recursive: true, force: true });
|
||||
deleted = true;
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
this.debug(
|
||||
`Failed to delete workspace directory ${workspaceDir} on attempt ${attempt}`,
|
||||
error
|
||||
);
|
||||
if (attempt === 5) {
|
||||
break;
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
}
|
||||
}
|
||||
|
||||
if (!deleted) {
|
||||
this.debug(`Failed to delete workspace directory ${workspaceDir}`);
|
||||
} else {
|
||||
this.debug(`Deleted workspace directory ${workspaceDir}`);
|
||||
}
|
||||
this.debug(`Deleted workspace directory ${workspaceDir}`);
|
||||
|
||||
eventBus.publish({
|
||||
type: 'workspace_deleted',
|
||||
|
||||
Reference in New Issue
Block a user