fix: handle cross-device issues with running otel collector (#4458)

This commit is contained in:
anthony bushong 2025-07-21 12:44:18 -07:00 committed by GitHub
parent 9bdcdf97d8
commit 74d0f4c79f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 1 deletions

View File

@ -111,6 +111,32 @@ export function writeJsonFile(filePath, data) {
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
}
export function moveBinary(source, destination) {
try {
fs.renameSync(source, destination);
} catch (error) {
if (error.code !== 'EXDEV') {
throw error;
}
// Handle a cross-device error: copy-to-temp-then-rename.
const destDir = path.dirname(destination);
const destFile = path.basename(destination);
const tempDest = path.join(destDir, `${destFile}.tmp`);
try {
fs.copyFileSync(source, tempDest);
fs.renameSync(tempDest, destination);
} catch (moveError) {
// If copy or rename fails, clean up the intermediate temp file.
if (fs.existsSync(tempDest)) {
fs.unlinkSync(tempDest);
}
throw moveError;
}
fs.unlinkSync(source);
}
}
export function waitForPort(port, timeout = 10000) {
return new Promise((resolve, reject) => {
const startTime = Date.now();
@ -248,7 +274,7 @@ export async function ensureBinary(
);
}
fs.renameSync(foundBinaryPath, executablePath);
moveBinary(foundBinaryPath, executablePath);
if (platform !== 'windows') {
fs.chmodSync(executablePath, '755');