Skip to content

Commit be99b87

Browse files
cipolleschicortinico
authored andcommitted
Fix replace-rncore-version to extract tarball via temp dir for EdenFS compatibility
Extract the rncore tarball to a temporary directory on a regular filesystem first, then move it to the final location. This avoids issues with partial tar extraction on EdenFS where extracting directly can silently produce incomplete results. Also adds extraction verification and mv/cp fallback logic. ## Changelog: [Internal] - Fix rncore tarball extraction on EdenFS by extracting to a temp dir first and moving to final location
1 parent 81223f2 commit be99b87

1 file changed

Lines changed: 66 additions & 8 deletions

File tree

packages/react-native/scripts/replace-rncore-version.js

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
const {spawnSync} = require('child_process');
1414
const fs = require('fs');
15+
const os = require('os');
16+
const path = require('path');
1517
const yargs = require('yargs');
1618

1719
const LAST_BUILD_FILENAME = 'React-Core-prebuilt/.last_build_configuration';
@@ -62,14 +64,70 @@ function replaceRNCoreConfiguration(
6264
const tarballURLPath = `${podsRoot}/ReactNativeCore-artifacts/reactnative-core-${version.toLowerCase()}-${configuration.toLowerCase()}.tar.gz`;
6365

6466
const finalLocation = 'React-Core-prebuilt';
65-
console.log('Preparing the final location', finalLocation);
66-
fs.rmSync(finalLocation, {force: true, recursive: true});
67-
fs.mkdirSync(finalLocation, {recursive: true});
68-
69-
console.log('Extracting the tarball', tarballURLPath);
70-
spawnSync('tar', ['-xf', tarballURLPath, '-C', finalLocation], {
71-
stdio: 'inherit',
72-
});
67+
68+
// Extract to a temporary directory on a regular filesystem first, then move
69+
// into the final location. This avoids issues with partial tar extraction on
70+
// certain filesystems (e.g. EdenFS) where extracting directly can silently
71+
// produce incomplete results.
72+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'rncore-'));
73+
const tmpExtractDir = path.join(tmpDir, 'React-Core-prebuilt');
74+
fs.mkdirSync(tmpExtractDir, {recursive: true});
75+
76+
try {
77+
console.log('Extracting the tarball to temp dir', tarballURLPath);
78+
const result = spawnSync('tar', ['-xf', tarballURLPath, '-C', tmpExtractDir], {
79+
stdio: 'inherit',
80+
});
81+
82+
if (result.status !== 0) {
83+
throw new Error(
84+
`tar extraction failed with exit code ${result.status}`,
85+
);
86+
}
87+
88+
// Verify extraction produced the expected xcframework structure
89+
const xcfwPath = path.join(tmpExtractDir, 'React.xcframework');
90+
const modulemapPath = path.join(
91+
xcfwPath,
92+
'Modules',
93+
'module.modulemap',
94+
);
95+
if (!fs.existsSync(modulemapPath)) {
96+
throw new Error(
97+
`Extraction verification failed: ${modulemapPath} not found`,
98+
);
99+
}
100+
101+
// Move from temp to final location
102+
console.log('Preparing the final location', finalLocation);
103+
fs.rmSync(finalLocation, {force: true, recursive: true});
104+
105+
// Use mv for an atomic-ish replacement. If the final location is on the
106+
// same filesystem as tmpDir this is a rename; otherwise it falls back to
107+
// copy + delete via spawnSync.
108+
const mvResult = spawnSync('mv', [tmpExtractDir, finalLocation], {
109+
stdio: 'inherit',
110+
});
111+
112+
if (mvResult.status !== 0) {
113+
// Fallback: copy recursively then remove temp
114+
console.log('mv failed, falling back to cp -R');
115+
fs.mkdirSync(finalLocation, {recursive: true});
116+
const cpResult = spawnSync(
117+
'cp',
118+
['-R', tmpExtractDir + '/.', finalLocation],
119+
{stdio: 'inherit'},
120+
);
121+
if (cpResult.status !== 0) {
122+
throw new Error(
123+
`cp fallback failed with exit code ${cpResult.status}`,
124+
);
125+
}
126+
}
127+
} finally {
128+
// Clean up temp directory
129+
fs.rmSync(tmpDir, {force: true, recursive: true});
130+
}
73131
}
74132

75133
function updateLastBuildConfiguration(configuration /*: string */) {

0 commit comments

Comments
 (0)