src: add NODE_PRESERVE_SYMLINKS environment variable

Add a way through environment variables to set the --preserve-symlinks
flag. Any non-null value of NODE_PRESERVE_SYMLINKS will enable symlinks.

PR-URL: https://github.com/nodejs/node/pull/8749
Fixes: https://github.com/nodejs/node/issues/8509
Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Marc Udoff
2016-09-20 18:21:44 -04:00
committed by Ilkka Myller
parent 929979d9d7
commit d3b1a2b4dd
3 changed files with 23 additions and 1 deletions

View File

@@ -287,6 +287,13 @@ added: v0.11.15
Data path for ICU (Intl object) data. Will extend linked-in data when compiled
with small-icu support.
### `NODE_PRESERVE_SYMLINKS=1`
<!-- YAML
added: REPLACEME
-->
When set to `1`, instructs the module loader to preserve symbolic links when
resolving and caching modules.
### `NODE_REPL_HISTORY=file`
<!-- YAML

View File

@@ -4202,6 +4202,11 @@ void Init(int* argc,
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1);
#endif
// Allow for environment set preserving symlinks.
if (auto preserve_symlinks = secure_getenv("NODE_PRESERVE_SYMLINKS")) {
config_preserve_symlinks = (*preserve_symlinks == '1');
}
// Parse a few arguments which are specific to Node.
int v8_argc;
const char** v8_argv;

View File

@@ -6,6 +6,7 @@ const path = require('path');
const fs = require('fs');
const exec = require('child_process').exec;
const spawn = require('child_process').spawn;
const util = require('util');
common.refreshTmpDir();
@@ -53,7 +54,16 @@ function test() {
const node = process.execPath;
const child = spawn(node, ['--preserve-symlinks', linkScript]);
child.on('close', function(code, signal) {
assert(!code);
assert.strictEqual(code, 0);
assert(!signal);
});
// Also verify that symlinks works for setting preserve via env variables
const childEnv = spawn(node, [linkScript], {
env: util._extend(process.env, {NODE_PRESERVE_SYMLINKS: '1'})
});
childEnv.on('close', function(code, signal) {
assert.strictEqual(code, 0);
assert(!signal);
});
}