Skip to content

Commit 0adff0d

Browse files
authored
fix: cleanup plugin install state on failed installations (#1113)
1 parent df17f04 commit 0adff0d

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/lib/installPlugin.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export default async function installPlugin(id, name, purchaseToken) {
1717
const loaderDialog = loader.create(title, strings.installing);
1818
let pluginDir;
1919
let pluginUrl;
20+
let state;
2021

2122
try {
2223
if (!(await fsOperation(PLUGIN_DIR).exists())) {
@@ -71,7 +72,7 @@ export default async function installPlugin(id, name, purchaseToken) {
7172
pluginDir = Url.join(PLUGIN_DIR, id);
7273
}
7374

74-
const state = await InstallState.new(id);
75+
state = await InstallState.new(id);
7576

7677
if (!(await fsOperation(pluginDir).exists())) {
7778
await fsOperation(PLUGIN_DIR).createDirectory(id);
@@ -115,9 +116,15 @@ export default async function installPlugin(id, name, purchaseToken) {
115116
}
116117
} catch (err) {
117118
try {
118-
await fsOperation(pluginDir).delete();
119-
} catch (error) {
120-
// ignore
119+
// Clear the install state if installation fails
120+
if (state) await state.clear();
121+
122+
// Delete the plugin directory if it was created
123+
if (pluginDir && (await fsOperation(pluginDir).exists())) {
124+
await fsOperation(pluginDir).delete();
125+
}
126+
} catch (cleanupError) {
127+
console.error("Cleanup failed:", cleanupError);
121128
}
122129
throw err;
123130
} finally {

src/lib/installState.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,16 @@ export default class InstallState {
8282
await fsOperation(url).delete();
8383
}
8484
}
85+
86+
async clear() {
87+
try {
88+
this.store = {};
89+
this.updatedStore = {};
90+
await fsOperation(this.storeUrl).writeFile("{}");
91+
} catch (error) {
92+
console.error("Failed to clear install state:", error);
93+
}
94+
}
8595
}
8696

8797
/**

0 commit comments

Comments
 (0)