From 89df2e3a75ab30e8bb2a4e5b10c990608a827298 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Wed, 25 Feb 2026 05:16:09 -0800 Subject: [PATCH] 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 --- .../runner/executables/hermesc.js | 33 ++++++++++++++++-- .../runner/executables/tester.js | 34 +++++++++++++++++-- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/private/react-native-fantom/runner/executables/hermesc.js b/private/react-native-fantom/runner/executables/hermesc.js index ebef91248eb..eddcc226ff2 100644 --- a/private/react-native-fantom/runner/executables/hermesc.js +++ b/private/react-native-fantom/runner/executables/hermesc.js @@ -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 {} } } diff --git a/private/react-native-fantom/runner/executables/tester.js b/private/react-native-fantom/runner/executables/tester.js index b3459c802f3..39fcd069fbf 100644 --- a/private/react-native-fantom/runner/executables/tester.js +++ b/private/react-native-fantom/runner/executables/tester.js @@ -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 {} } }