Skip to content

Commit

Permalink
fix: deleting a model generates an error (#677)
Browse files Browse the repository at this point in the history
Fixes #649

Signed-off-by: Jeff MAURY <jmaury@redhat.com>
  • Loading branch information
jeffmaury committed Mar 26, 2024
1 parent 593dd88 commit 2409db5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions packages/backend/src/managers/modelsManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,17 @@ test('deleteLocalModel deletes the model folder', async () => {
await manager.deleteLocalModel('model-id-1');
// check that the model's folder is removed from disk
if (process.platform === 'win32') {
expect(rmSpy).toBeCalledWith('C:\\home\\user\\aistudio\\models\\model-id-1', { recursive: true });
expect(rmSpy).toBeCalledWith('C:\\home\\user\\aistudio\\models\\model-id-1', {
recursive: true,
force: true,
maxRetries: 3,
});
} else {
expect(rmSpy).toBeCalledWith('/home/user/aistudio/models/model-id-1', { recursive: true });
expect(rmSpy).toBeCalledWith('/home/user/aistudio/models/model-id-1', {
recursive: true,
force: true,
maxRetries: 3,
});
}
expect(postMessageMock).toHaveBeenCalledTimes(3);
// check that a new state is sent with the model removed
Expand Down Expand Up @@ -430,9 +438,17 @@ test('deleteLocalModel fails to delete the model folder', async () => {
await manager.deleteLocalModel('model-id-1');
// check that the model's folder is removed from disk
if (process.platform === 'win32') {
expect(rmSpy).toBeCalledWith('C:\\home\\user\\aistudio\\models\\model-id-1', { recursive: true });
expect(rmSpy).toBeCalledWith('C:\\home\\user\\aistudio\\models\\model-id-1', {
recursive: true,
force: true,
maxRetries: 3,
});
} else {
expect(rmSpy).toBeCalledWith('/home/user/aistudio/models/model-id-1', { recursive: true });
expect(rmSpy).toBeCalledWith('/home/user/aistudio/models/model-id-1', {
recursive: true,
force: true,
maxRetries: 3,
});
}
expect(postMessageMock).toHaveBeenCalledTimes(3);
// check that a new state is sent with the model non removed
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/managers/modelsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export class ModelsManager implements Disposable {
model.state = 'deleting';
await this.sendModelsInfo();
try {
await fs.promises.rm(modelDir, { recursive: true });
await fs.promises.rm(modelDir, { recursive: true, force: true, maxRetries: 3 });
this.telemetry.logUsage('model.delete', { 'model.id': modelId });
model.file = model.state = undefined;
} catch (err: unknown) {
Expand Down

0 comments on commit 2409db5

Please sign in to comment.