summaryrefslogtreecommitdiff
path: root/scripts/telemetry_utils.js
diff options
context:
space:
mode:
authoranthony bushong <[email protected]>2025-07-21 12:44:18 -0700
committerGitHub <[email protected]>2025-07-21 19:44:18 +0000
commit74d0f4c79fbc035804c80b6f594d42dcb466572a (patch)
treecb0e20c63edbcb5a59778dc76173ae26376fba91 /scripts/telemetry_utils.js
parent9bdcdf97d883d860a1552a5da5b890e8a7ec6b8a (diff)
fix: handle cross-device issues with running otel collector (#4458)
Diffstat (limited to 'scripts/telemetry_utils.js')
-rw-r--r--scripts/telemetry_utils.js28
1 files changed, 27 insertions, 1 deletions
diff --git a/scripts/telemetry_utils.js b/scripts/telemetry_utils.js
index a37c6fd1..66f14745 100644
--- a/scripts/telemetry_utils.js
+++ b/scripts/telemetry_utils.js
@@ -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');