| 113 | } |
| 114 | |
| 115 | export function moveBinary(source, destination) { |
| 116 | try { |
| 117 | fs.renameSync(source, destination); |
| 118 | } catch (error) { |
| 119 | if (error.code !== 'EXDEV') { |
| 120 | throw error; |
| 121 | } |
| 122 | // Handle a cross-device error: copy-to-temp-then-rename. |
| 123 | const destDir = path.dirname(destination); |
| 124 | const destFile = path.basename(destination); |
| 125 | const tempDest = path.join(destDir, `${destFile}.tmp`); |
| 126 | |
| 127 | try { |
| 128 | fs.copyFileSync(source, tempDest); |
| 129 | fs.renameSync(tempDest, destination); |
| 130 | } catch (moveError) { |
| 131 | // If copy or rename fails, clean up the intermediate temp file. |
| 132 | if (fs.existsSync(tempDest)) { |
| 133 | fs.unlinkSync(tempDest); |
| 134 | } |
| 135 | throw moveError; |
| 136 | } |
| 137 | fs.unlinkSync(source); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | export function waitForPort(port, timeout = 10000) { |
| 142 | return new Promise((resolve, reject) => { |