Skip to content

🎥 Make videos programmatically with React

`@remotion/renderer`: Fix Rust binary running into EACCESS error on Dev Container

Jonny Burger324d91866d90
diff --git a/packages/renderer/src/compositor/make-file-executable.ts b/packages/renderer/src/compositor/make-file-executable.ts
index 394a8d3889..8d20253868 100644
--- a/packages/renderer/src/compositor/make-file-executable.ts
+++ b/packages/renderer/src/compositor/make-file-executable.ts
@@ -1,10 +1,51 @@
/* eslint-disable no-bitwise */
-import {accessSync, chmodSync, constants} from 'node:fs';
+import {accessSync, chmodSync, constants, statSync} from 'node:fs';
+
+const hasPermissions = (p: string) => {
+ if (process.platform !== 'linux') {
+ try {
+ accessSync(p, constants.X_OK);
+ return true;
+ } catch {
+ return false;
+ }
+ }
+
+ // On Linux, checking file permissions, because Node.js
+ // seems buggy: https://github.com/remotion-dev/remotion/issues/3587
+ const stats = statSync(p);
+ const {mode} = stats;
+ const othersHaveExecutePermission = Boolean(mode & 0o001);
+
+ if (othersHaveExecutePermission) {
+ return true;
+ }
+
+ if (!process.getuid || !process.getgid) {
+ throw new Error(
+ 'Cannot check permissions on Linux without process.getuid and process.getgid',
+ );
+ }
+
+ const uid = process.getuid();
+ const gid = process.getgid();
+
+ const isOwner = uid === stats.uid;
+ const isGroup = gid === stats.gid;
+
+ const ownerHasExecutePermission = Boolean(mode & 0o100);
+ const groupHasExecutePermission = Boolean(mode & 0o010);
+
+ const canExecute =
+ (isOwner && ownerHasExecutePermission) ||
+ (isGroup && groupHasExecutePermission);
+
+ return canExecute;
+};
export const makeFileExecutableIfItIsNot = (path: string) => {
- try {
- accessSync(path, constants.X_OK);
- } catch (err) {
+ const hasPermissionsResult = hasPermissions(path);
+ if (!hasPermissionsResult) {
chmodSync(path, 0o755);
}
};