| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 60f27f9 commit 1555ced
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -163,6 +163,13 @@ A stream to push an array into a REPL | |||
| 163 | 163 | ||
| 164 | 164 | Blocks for `time` amount of time. | |
| 165 | 165 | ||
| 166 | + ### canCreateSymLink | ||
| 167 | + API to indicate whether the current running process can create | ||
| 168 | + symlinks. On Windows, this returns false if the process running | ||
| 169 | + doesn't have privileges to create symlinks (specifically | ||
| 170 | + [SeCreateSymbolicLinkPrivilege](https://msdn.microsoft.com/en-us/library/windows/desktop/bb530716(v=vs.85).aspx)). | ||
| 171 | + On non-Windows platforms, this currently returns true. | ||
| 172 | + | ||
| 166 | 173 | ### ddCommand(filename, kilobytes) | |
| 167 | 174 | * return [<Object>](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object) | |
| 168 | 175 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ const child_process = require('child_process'); | |||
| 8 | 8 | const stream = require('stream'); | |
| 9 | 9 | const util = require('util'); | |
| 10 | 10 | const Timer = process.binding('timer_wrap').Timer; | |
| 11 | + const execSync = require('child_process').execSync; | ||
| 11 | 12 | ||
| 12 | 13 | const testRoot = process.env.NODE_TEST_DIR ? | |
| 13 | 14 | fs.realpathSync(process.env.NODE_TEST_DIR) : __dirname; | |
@@ -438,6 +439,34 @@ exports.fileExists = function(pathname) { | |||
| 438 | 439 | } | |
| 439 | 440 | }; | |
| 440 | 441 | ||
| 442 | + exports.canCreateSymLink = function() { | ||
| 443 | + // On Windows, creating symlinks requires admin privileges. | ||
| 444 | + // We'll only try to run symlink test if we have enough privileges. | ||
| 445 | + // On other platforms, creating symlinks shouldn't need admin privileges | ||
| 446 | + if (exports.isWindows) { | ||
| 447 | + // whoami.exe needs to be the one from System32 | ||
| 448 | + // If unix tools are in the path, they can shadow the one we want, | ||
| 449 | + // so use the full path while executing whoami | ||
| 450 | + const whoamiPath = path.join(process.env['SystemRoot'], | ||
| 451 | + 'System32', 'whoami.exe'); | ||
| 452 | + | ||
| 453 | + let err = false; | ||
| 454 | + let output = ''; | ||
| 455 | + | ||
| 456 | + try { | ||
| 457 | + output = execSync(whoamiPath + ' /priv', { timout: 1000 }); | ||
| 458 | + } catch (e) { | ||
| 459 | + err = true; | ||
| 460 | + } finally { | ||
| 461 | + if (err || !output.includes('SeCreateSymbolicLinkPrivilege')) { | ||
| 462 | + return false; | ||
| 463 | + } | ||
| 464 | + } | ||
| 465 | + } | ||
| 466 | + | ||
| 467 | + return true; | ||
| 468 | + }; | ||
| 469 | + | ||
| 441 | 470 | function fail(msg) { | |
| 442 | 471 | assert.fail(null, null, msg); | |
| 443 | 472 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,7 +29,7 @@ common.refreshTmpDir(); | |||
| 29 | 29 | assert.doesNotThrow(() => fs.readdirSync(__dirname, options)); | |
| 30 | 30 | } | |
| 31 | 31 | ||
| 32 | - { | ||
| 32 | + if (common.canCreateSymLink()) { | ||
| 33 | 33 | const sourceFile = path.resolve(common.tmpDir, 'test-readlink'); | |
| 34 | 34 | const linkFile = path.resolve(common.tmpDir, 'test-readlink-link'); | |
| 35 | 35 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,20 +3,13 @@ const common = require('../common'); | |||
| 3 | 3 | const assert = require('assert'); | |
| 4 | 4 | const path = require('path'); | |
| 5 | 5 | const fs = require('fs'); | |
| 6 | - const exec = require('child_process').exec; | ||
| 7 | 6 | ||
| 8 | 7 | var linkTime; | |
| 9 | 8 | var fileTime; | |
| 10 | 9 | ||
| 11 | - if (common.isWindows) { | ||
| 12 | - // On Windows, creating symlinks requires admin privileges. | ||
| 13 | - // We'll only try to run symlink test if we have enough privileges. | ||
| 14 | - exec('whoami /priv', function(err, o) { | ||
| 15 | - if (err || !o.includes('SeCreateSymbolicLinkPrivilege')) { | ||
| 16 | - common.skip('insufficient privileges'); | ||
| 17 | - return; | ||
| 18 | - } | ||
| 19 | - }); | ||
| 10 | + if (!common.canCreateSymLink()) { | ||
| 11 | + common.skip('insufficient privileges'); | ||
| 12 | + return; | ||
| 20 | 13 | } | |
| 21 | 14 | ||
| 22 | 15 | common.refreshTmpDir(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments