MCPcopy Index your code
hub / github.com/shelljs/shelljs / execSync

Function execSync

src/exec.js:20–134  ·  view source on GitHub ↗
(cmd, opts, pipe)

Source from the content-addressed store, hash-verified

18// We use this function to run `exec` synchronously while also providing realtime
19// output.
20function execSync(cmd, opts, pipe) {
21 if (!common.config.execPath) {
22 try {
23 common.error('Unable to find a path to the node binary. Please manually set config.execPath');
24 } catch (e) {
25 if (opts.fatal) {
26 throw e;
27 }
28
29 return;
30 }
31 }
32
33 var tempDir = _tempDir();
34 var paramsFile = path.join(tempDir, common.randomFileName());
35 var stderrFile = path.join(tempDir, common.randomFileName());
36 var stdoutFile = path.join(tempDir, common.randomFileName());
37
38 opts = common.extend({
39 silent: common.config.silent,
40 fatal: common.config.fatal, // TODO(nfischer): this and the line above are probably unnecessary
41 cwd: _pwd().toString(),
42 env: process.env,
43 maxBuffer: DEFAULT_MAXBUFFER_SIZE,
44 encoding: 'utf8',
45 }, opts);
46
47 if (fs.existsSync(paramsFile)) common.unlinkSync(paramsFile);
48 if (fs.existsSync(stderrFile)) common.unlinkSync(stderrFile);
49 if (fs.existsSync(stdoutFile)) common.unlinkSync(stdoutFile);
50
51 opts.cwd = path.resolve(opts.cwd);
52
53 var paramsToSerialize = {
54 command: cmd,
55 execOptions: opts,
56 pipe,
57 stdoutFile,
58 stderrFile,
59 };
60
61 // Create the files and ensure these are locked down (for read and write) to
62 // the current user. The main concerns here are:
63 //
64 // * If we execute a command which prints sensitive output, then
65 // stdoutFile/stderrFile must not be readable by other users.
66 // * paramsFile must not be readable by other users, or else they can read it
67 // to figure out the path for stdoutFile/stderrFile and create these first
68 // (locked down to their own access), which will crash exec() when it tries
69 // to write to the files.
70 function writeFileLockedDown(filePath, data) {
71 fs.writeFileSync(filePath, data, {
72 encoding: 'utf8',
73 mode: parseInt('600', 8),
74 });
75 }
76 writeFileLockedDown(stdoutFile, '');
77 writeFileLockedDown(stderrFile, '');

Callers 1

_execFunction · 0.85

Calls 3

_tempDirFunction · 0.85
_pwdFunction · 0.85
writeFileLockedDownFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…