@@ -129,15 +129,59 @@ export class Installer extends EventEmitter {
129
129
public async remove ( version : string ) : Promise < void > {
130
130
const d = debug ( 'fiddle-core:Installer:remove' ) ;
131
131
d ( version ) ;
132
- // remove the zipfile
133
- const zip = path . join ( this . paths . electronDownloads , getZipName ( version ) ) ;
134
- await fs . remove ( zip ) ;
132
+ let isBinaryDeleted = false ;
133
+ // utility to re-run removal functions upon failure
134
+ // due to windows filesystem lockfile jank
135
+ const rerunner = async (
136
+ path : string ,
137
+ func : ( path : string ) => Promise < void > ,
138
+ counter = 1 ,
139
+ ) : Promise < boolean > => {
140
+ try {
141
+ await func ( path ) ;
142
+ return true ;
143
+ } catch ( error ) {
144
+ console . warn (
145
+ `Installer: failed to run ${ func . name } for ${ version } , but failed` ,
146
+ error ,
147
+ ) ;
148
+ if ( counter < 4 ) {
149
+ console . log ( `Installer: Trying again to run ${ func . name } ` ) ;
150
+ await rerunner ( path , func , counter + 1 ) ;
151
+ }
152
+ }
153
+ return false ;
154
+ } ;
155
+
156
+ const binaryCleaner = async ( path : string ) => {
157
+ if ( fs . existsSync ( path ) ) {
158
+ await fs . remove ( path ) ;
159
+ }
160
+ } ;
161
+ // get the zip path
162
+ const zipPath = path . join (
163
+ this . paths . electronDownloads ,
164
+ getZipName ( version ) ,
165
+ ) ;
166
+ const isZipDeleted = await rerunner ( zipPath , binaryCleaner ) ;
135
167
136
168
// maybe uninstall it
137
- if ( this . installedVersion === version )
138
- await fs . remove ( this . paths . electronInstall ) ;
169
+ if ( this . installedVersion === version ) {
170
+ isBinaryDeleted = await rerunner (
171
+ this . paths . electronInstall ,
172
+ binaryCleaner ,
173
+ ) ;
174
+ } else {
175
+ // If the current version binary doesn't exists
176
+ isBinaryDeleted = true ;
177
+ }
139
178
140
- this . setState ( version , 'missing' ) ;
179
+ if ( isZipDeleted && isBinaryDeleted ) {
180
+ this . setState ( version , 'missing' ) ;
181
+ } else {
182
+ // Ideally the execution shouldn't reach this point
183
+ console . warn ( `Installer: Failed to remove version ${ version } ` ) ;
184
+ }
141
185
}
142
186
143
187
/** The current Electron installation, if any. */
0 commit comments