@remotion/renderer
Version:
Render Remotion videos using Node.js or Bun
45 lines (44 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeFileExecutableIfItIsNot = void 0;
/* eslint-disable no-bitwise */
const node_fs_1 = require("node:fs");
const hasPermissions = (p) => {
// We observe that with Bun, the problem also happens in macOS
if (process.platform !== 'linux' && process.platform !== 'darwin') {
try {
(0, node_fs_1.accessSync)(p, node_fs_1.constants.X_OK);
return true;
}
catch (_a) {
return false;
}
}
// On Linux, checking file permissions, because Node.js
// seems buggy: https://github.com/remotion-dev/remotion/issues/3587
const stats = (0, node_fs_1.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;
};
const makeFileExecutableIfItIsNot = (path) => {
const hasPermissionsResult = hasPermissions(path);
if (!hasPermissionsResult) {
(0, node_fs_1.chmodSync)(path, 0o755);
}
};
exports.makeFileExecutableIfItIsNot = makeFileExecutableIfItIsNot;