Skip to content

Commit e3afba4

Browse files
authored
fix: Set executable permissions on ripgrep binaries at runtime (#267)
Zip archives don't reliably preserve Unix file permissions across platforms. This causes EACCES errors when ripgrep binaries are extracted without executable permissions on macOS/Linux. Solution: ripgrep-wrapper.js now sets 0o755 permissions at runtime when the module is first loaded, ensuring binaries are always executable regardless of how they were extracted. Fixes: spawn rg-aarch64-apple-darwin EACCES on macOS
1 parent 973202d commit e3afba4

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

scripts/build-mcpb.cjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,9 @@ try {
160160
const src = path.join(ripgrepBinSrc, binary);
161161
const dest = path.join(ripgrepBinDest, binary);
162162
fs.copyFileSync(src, dest);
163-
// Preserve executable permissions
163+
// Set executable permissions (for development/testing)
164+
// Note: Zip archives don't preserve permissions reliably, so ripgrep-wrapper.js
165+
// also sets permissions at runtime to ensure compatibility after extraction
164166
if (!binary.endsWith('.exe')) {
165167
fs.chmodSync(dest, 0o755);
166168
}

scripts/ripgrep-wrapper.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,32 @@ const binaryName = isWindows ? `rg-${target}.exe` : `rg-${target}`;
3434
// __dirname is lib/, so go up one level to reach bin/
3535
const rgPath = path.join(__dirname, '..', 'bin', binaryName);
3636

37-
// Verify binary exists
37+
// Verify binary exists and ensure executable permissions
3838
if (!fs.existsSync(rgPath)) {
3939
// Try fallback to original rg location
4040
const fallbackPath = path.join(__dirname, '..', 'bin', isWindows ? 'rg.exe' : 'rg');
4141
if (fs.existsSync(fallbackPath)) {
42+
// Ensure executable permissions on Unix systems
43+
if (!isWindows) {
44+
try {
45+
fs.chmodSync(fallbackPath, 0o755);
46+
} catch (err) {
47+
// Ignore permission errors - might not have write access
48+
}
49+
}
4250
module.exports.rgPath = fallbackPath;
4351
} else {
4452
throw new Error(`ripgrep binary not found for platform ${target}: ${rgPath}`);
4553
}
4654
} else {
55+
// Ensure executable permissions on Unix systems
56+
// This fixes issues when extracting from zip archives that don't preserve permissions
57+
if (!isWindows) {
58+
try {
59+
fs.chmodSync(rgPath, 0o755);
60+
} catch (err) {
61+
// Ignore permission errors - might not have write access
62+
}
63+
}
4764
module.exports.rgPath = rgPath;
4865
}

0 commit comments

Comments
 (0)