@@ -5,6 +5,7 @@ const fs = require('../lib/wrapped-fs').default;
5
5
const os = require ( 'os' ) ;
6
6
const path = require ( 'path' ) ;
7
7
const rimraf = require ( 'rimraf' ) ;
8
+ const { execSync } = require ( 'child_process' ) ;
8
9
9
10
const asar = require ( '..' ) ;
10
11
const compDirs = require ( './util/compareDirectories' ) ;
@@ -17,6 +18,27 @@ async function assertPackageListEquals(actualList, expectedFilename) {
17
18
return compFileLists ( actualList . join ( '\n' ) , expected ) ;
18
19
}
19
20
21
+ function canCreateSymLink ( ) {
22
+ // On Windows, creating symlinks requires admin privileges.
23
+ // We'll only try to run symlink test if we have enough privileges.
24
+ // On other platforms, creating symlinks shouldn't need admin privileges
25
+ if ( process . platform === 'win32' ) {
26
+ // whoami.exe needs to be the one from System32
27
+ // If unix tools are in the path, they can shadow the one we want,
28
+ // so use the full path while executing whoami
29
+ const whoamiPath = path . join ( process . env . SystemRoot , 'System32' , 'whoami.exe' ) ;
30
+
31
+ try {
32
+ const output = execSync ( `${ whoamiPath } /priv` , { timeout : 1000 } ) ;
33
+ return output . includes ( 'SeCreateSymbolicLinkPrivilege' ) ;
34
+ } catch {
35
+ return false ;
36
+ }
37
+ }
38
+ // On non-Windows platforms, this always returns `true`
39
+ return true ;
40
+ }
41
+
20
42
describe ( 'api' , function ( ) {
21
43
beforeEach ( ( ) => {
22
44
rimraf . sync ( path . join ( __dirname , '..' , 'tmp' ) , fs ) ;
@@ -108,6 +130,8 @@ describe('api', function () {
108
130
return compDirs ( 'tmp/extractthis-unpack-dir-api/' , 'test/expected/extractthis' ) ;
109
131
} ) ;
110
132
it ( 'should extract an archive with symlink' , async ( ) => {
133
+ assert . strictEqual ( canCreateSymLink ( ) , true ) ;
134
+
111
135
await asar . createPackageWithOptions (
112
136
'test/input/packthis-with-symlink/' ,
113
137
'tmp/packthis-with-symlink.asar' ,
@@ -120,6 +144,8 @@ describe('api', function () {
120
144
) ;
121
145
} ) ;
122
146
it ( 'should extract an archive with symlink having the same prefix' , async ( ) => {
147
+ assert . strictEqual ( canCreateSymLink ( ) , true ) ;
148
+
123
149
await asar . createPackageWithOptions (
124
150
'test/input/packthis-with-symlink-same-prefix/' ,
125
151
'tmp/packthis-with-symlink-same-prefix.asar' ,
0 commit comments