Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4b2e886

Browse filesBrowse files
cjihrigMylesBorins
authored andcommitted
test: use common.canCreateSymLink() consistently
This commit replaces two ad hoc symlink permission tests with common.canCreateSymLink(). PR-URL: #20540 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent b6168bb commit 4b2e886
Copy full SHA for 4b2e886

File tree

Expand file treeCollapse file tree

2 files changed

+4
-34
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+4
-34
lines changed
Open diff view settings
Collapse file

‎test/parallel/test-fs-realpath.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-fs-realpath.js
+2-19Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ const tmpdir = require('../common/tmpdir');
2727
const assert = require('assert');
2828
const fs = require('fs');
2929
const path = require('path');
30-
const exec = require('child_process').exec;
3130
let async_completed = 0;
3231
let async_expected = 0;
3332
const unlink = [];
34-
let skipSymlinks = false;
33+
const skipSymlinks = !common.canCreateSymLink();
3534
const tmpDir = tmpdir.path;
3635

3736
tmpdir.refresh();
@@ -45,25 +44,9 @@ if (common.isWindows) {
4544
assert
4645
.strictEqual(path_left.toLowerCase(), path_right.toLowerCase(), message);
4746
};
48-
49-
// On Windows, creating symlinks requires admin privileges.
50-
// We'll only try to run symlink test if we have enough privileges.
51-
try {
52-
exec('whoami /priv', function(err, o) {
53-
if (err || !o.includes('SeCreateSymbolicLinkPrivilege')) {
54-
skipSymlinks = true;
55-
}
56-
runTest();
57-
});
58-
} catch (er) {
59-
// better safe than sorry
60-
skipSymlinks = true;
61-
process.nextTick(runTest);
62-
}
63-
} else {
64-
process.nextTick(runTest);
6547
}
6648

49+
process.nextTick(runTest);
6750

6851
function tmp(p) {
6952
return path.join(tmpDir, p);
Collapse file

‎test/parallel/test-trace-events-fs-sync.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-trace-events-fs-sync.js
+2-15Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,8 @@ const traceFile = 'node_trace.1.log';
99

1010
let gid = 1;
1111
let uid = 1;
12-
let skipSymlinks = false;
1312

14-
// On Windows, creating symlinks requires admin privileges.
15-
// We'll check if we have enough privileges.
16-
if (common.isWindows) {
17-
try {
18-
const o = cp.execSync('whoami /priv');
19-
if (!o.includes('SeCreateSymbolicLinkPrivilege')) {
20-
skipSymlinks = true;
21-
}
22-
} catch (er) {
23-
// better safe than sorry
24-
skipSymlinks = true;
25-
}
26-
} else {
13+
if (!common.isWindows) {
2714
gid = process.getgid();
2815
uid = process.getuid();
2916
}
@@ -111,7 +98,7 @@ tests['fs.sync.write'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
11198

11299
// On windows, we need permissions to test symlink and readlink.
113100
// We'll only try to run these tests if we have enough privileges.
114-
if (!skipSymlinks) {
101+
if (common.canCreateSymLink()) {
115102
tests['fs.sync.symlink'] = 'fs.writeFileSync("fs.txt", "123", "utf8");' +
116103
'fs.symlinkSync("fs.txt", "linkx");' +
117104
'fs.unlinkSync("linkx");' +

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.