File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -240,12 +240,30 @@ async function downloadBinary(version) {
240240 throw new Error ( `Unsupported platform: ${ process . platform } ${ process . arch } ` )
241241 }
242242
243- const downloadUrl = `${ process . env . NEXT_PUBLIC_CODEBUFF_APP_URL || 'https://codebuff.com' } /api/releases/download/${ version } /${ fileName } `
243+ const downloadUrl = `${
244+ process . env . NEXT_PUBLIC_CODEBUFF_APP_URL || 'https://codebuff.com'
245+ } /api/releases/download/${ version } /${ fileName } `
244246
245247 fs . mkdirSync ( CONFIG . configDir , { recursive : true } )
246248
247249 if ( fs . existsSync ( CONFIG . binaryPath ) ) {
248- fs . unlinkSync ( CONFIG . binaryPath )
250+ try {
251+ fs . unlinkSync ( CONFIG . binaryPath )
252+ } catch ( err ) {
253+ // Fallback: try renaming the locked/undeletable binary
254+ const backupPath = CONFIG . binaryPath + `.old.${ Date . now ( ) } `
255+
256+ try {
257+ fs . renameSync ( CONFIG . binaryPath , backupPath )
258+ } catch ( renameErr ) {
259+ // If we can't unlink OR rename, we can't safely proceed
260+ throw new Error (
261+ `Failed to replace existing binary. ` +
262+ `unlink error: ${ err . code || err . message } , ` +
263+ `rename error: ${ renameErr . code || renameErr . message } ` ,
264+ )
265+ }
266+ }
249267 }
250268
251269 term . write ( 'Downloading...' )
You can’t perform that action at this time.
0 commit comments