@@ -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,28 @@ 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
+ console . log ( output . toString ( ) ) ;
34
+ return output . includes ( 'SeCreateSymbolicLinkPrivilege' ) ;
35
+ } catch {
36
+ return false ;
37
+ }
38
+ }
39
+ // On non-Windows platforms, this always returns `true`
40
+ return true ;
41
+ }
42
+
20
43
describe ( 'api' , function ( ) {
21
44
beforeEach ( ( ) => {
22
45
rimraf . sync ( path . join ( __dirname , '..' , 'tmp' ) , fs ) ;
@@ -108,6 +131,8 @@ describe('api', function () {
108
131
return compDirs ( 'tmp/extractthis-unpack-dir-api/' , 'test/expected/extractthis' ) ;
109
132
} ) ;
110
133
it ( 'should extract an archive with symlink' , async ( ) => {
134
+ assert . strictEqual ( canCreateSymLink ( ) , true ) ;
135
+
111
136
await asar . createPackageWithOptions (
112
137
'test/input/packthis-with-symlink/' ,
113
138
'tmp/packthis-with-symlink.asar' ,
@@ -120,6 +145,8 @@ describe('api', function () {
120
145
) ;
121
146
} ) ;
122
147
it ( 'should extract an archive with symlink having the same prefix' , async ( ) => {
148
+ assert . strictEqual ( canCreateSymLink ( ) , true ) ;
149
+
123
150
await asar . createPackageWithOptions (
124
151
'test/input/packthis-with-symlink-same-prefix/' ,
125
152
'tmp/packthis-with-symlink-same-prefix.asar' ,
0 commit comments