fix: handle cross-device issues with running otel collector (#4458)
This commit is contained in:
parent
9bdcdf97d8
commit
74d0f4c79f
|
@ -111,6 +111,32 @@ export function writeJsonFile(filePath, data) {
|
||||||
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
|
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) {
|
export function waitForPort(port, timeout = 10000) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const startTime = Date.now();
|
const startTime = Date.now();
|
||||||
|
@ -248,7 +274,7 @@ export async function ensureBinary(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.renameSync(foundBinaryPath, executablePath);
|
moveBinary(foundBinaryPath, executablePath);
|
||||||
|
|
||||||
if (platform !== 'windows') {
|
if (platform !== 'windows') {
|
||||||
fs.chmodSync(executablePath, '755');
|
fs.chmodSync(executablePath, '755');
|
||||||
|
|
Loading…
Reference in New Issue