Fix Buck2 --out permission errors on macOS for claude code (#55736)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/55736

changelog: [internal]

On macOS with EdenFS backed directories, Buck2's --out flag fails with "Operation not permitted" error.

This fix works around the issue by:
1. Building to a temp directory outside the repo (os.tmpdir())
2. Removing extended attributes with `xattr -rc` on macOS

Reviewed By: cipolleschi

Differential Revision: D92078500

fbshipit-source-id: 437734c068e4bf20a4f8e570e1184565810154d3
This commit is contained in:
Samuel Susla authored and meta-codesync[bot] committed 2026-02-25 05:16:09 -08:00
1 parent 34fb790bff
commit 89df2e3a75
2 files changed
+63 -4

No files matched your search

+31 -2
View File
@@ -21,6 +21,7 @@ import {
runCommandSync,
} from '../utils';
import fs from 'fs';
import os from 'os';
import path from 'path';
type TesterOptions = Readonly<{
@@ -44,7 +45,13 @@ export function build(options: TesterOptions): void {
return;
}
const tmpPath = destPath + '-' + Date.now();
// Use system temp directory outside the repo to avoid macOS extended
// attribute issues with EdenFS/NFS-backed directories
const tmpPath = path.join(
os.tmpdir(),
`hermesc-${Date.now()}-${process.pid}`,
);
const destTmpPath = destPath + '-' + Date.now() + '-' + process.pid;
try {
const result = runBuck2Sync([
@@ -65,11 +72,33 @@ export function build(options: TesterOptions): void {
return;
}
fs.renameSync(tmpPath, destPath);
// Remove extended attributes to avoid "Operation not permitted" errors
// when copying to EdenFS/NFS-backed directories on macOS
if (os.platform() === 'darwin') {
runCommandSync('xattr', ['-rc', tmpPath]);
}
fs.copyFileSync(tmpPath, destTmpPath);
try {
fs.renameSync(destTmpPath, destPath);
} catch (e: unknown) {
// Another process may have created the file already - that's fine
const code =
typeof e === 'object' && e != null && typeof e.code === 'string'
? e.code
: null;
if (code !== 'EEXIST' && !fs.existsSync(destPath)) {
throw e;
}
}
} finally {
try {
fs.unlinkSync(tmpPath);
} catch {}
try {
fs.unlinkSync(destTmpPath);
} catch {}
}
}
+32 -2
View File
@@ -19,8 +19,10 @@ import {
runBuck2,
runBuck2Sync,
runCommand,
runCommandSync,
} from '../utils';
import fs from 'fs';
import os from 'os';
import path from 'path';
const FANTOM_TESTER_BUCK_TARGET =
@@ -47,7 +49,13 @@ export function build(options: TesterOptions): void {
return;
}
const tmpPath = destPath + '-' + Date.now();
// Use system temp directory outside the repo to avoid macOS extended
// attribute issues with EdenFS/NFS-backed directories
const tmpPath = path.join(
os.tmpdir(),
`fantom-tester-${Date.now()}-${process.pid}`,
);
const destTmpPath = destPath + '-' + Date.now() + '-' + process.pid;
try {
const result = runBuck2Sync([
@@ -68,11 +76,33 @@ export function build(options: TesterOptions): void {
return;
}
fs.renameSync(tmpPath, destPath);
// Remove extended attributes to avoid "Operation not permitted" errors
// when copying to EdenFS/NFS-backed directories on macOS
if (os.platform() === 'darwin') {
runCommandSync('xattr', ['-rc', tmpPath]);
}
fs.copyFileSync(tmpPath, destTmpPath);
try {
fs.renameSync(destTmpPath, destPath);
} catch (e: unknown) {
// Another process may have created the file already - that's fine
const code =
typeof e === 'object' && e != null && typeof e.code === 'string'
? e.code
: null;
if (code !== 'EEXIST' && !fs.existsSync(destPath)) {
throw e;
}
}
} finally {
try {
fs.unlinkSync(tmpPath);
} catch {}
try {
fs.unlinkSync(destTmpPath);
} catch {}
}
}