1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
4
- var fs = require ( 'fs' ) ;
5
- var path = require ( 'path' ) ;
6
- var exec = require ( 'child_process' ) . exec ;
2
+ const common = require ( '../common' ) ;
3
+ const assert = require ( 'assert' ) ;
4
+ const fs = require ( 'fs' ) ;
5
+ const path = require ( 'path' ) ;
6
+ const exec = require ( 'child_process' ) . exec ;
7
7
var async_completed = 0 , async_expected = 0 , unlink = [ ] ;
8
8
var skipSymlinks = false ;
9
9
10
10
common . refreshTmpDir ( ) ;
11
11
12
12
var root = '/' ;
13
- var assertEqualPath = assert . equal ;
13
+ var assertEqualPath = assert . strictEqual ;
14
14
if ( common . isWindows ) {
15
15
// something like "C:\\"
16
16
root = process . cwd ( ) . substr ( 0 , 3 ) ;
17
17
assertEqualPath = function ( path_left , path_right , message ) {
18
- assert . equal ( path_left . toLowerCase ( ) , path_right . toLowerCase ( ) , message ) ;
18
+ assert
19
+ . strictEqual ( path_left . toLowerCase ( ) , path_right . toLowerCase ( ) , message ) ;
19
20
} ;
20
21
21
22
// On Windows, creating symlinks requires admin privileges.
22
23
// We'll only try to run symlink test if we have enough privileges.
23
24
try {
24
25
exec ( 'whoami /priv' , function ( err , o ) {
25
- if ( err || o . indexOf ( 'SeCreateSymbolicLinkPrivilege' ) == - 1 ) {
26
+ if ( err || ! o . includes ( 'SeCreateSymbolicLinkPrivilege' ) ) {
26
27
skipSymlinks = true ;
27
28
}
28
29
runTest ( ) ;
@@ -41,8 +42,8 @@ function tmp(p) {
41
42
return path . join ( common . tmpDir , p ) ;
42
43
}
43
44
44
- var targetsAbsDir = path . join ( common . tmpDir , 'targets' ) ;
45
- var tmpAbsDir = common . tmpDir ;
45
+ const targetsAbsDir = path . join ( common . tmpDir , 'targets' ) ;
46
+ const tmpAbsDir = common . tmpDir ;
46
47
47
48
// Set up targetsAbsDir and expected subdirectories
48
49
fs . mkdirSync ( targetsAbsDir ) ;
@@ -91,7 +92,7 @@ function test_simple_relative_symlink(callback) {
91
92
fs . symlinkSync ( t [ 1 ] , t [ 0 ] , 'file' ) ;
92
93
unlink . push ( t [ 0 ] ) ;
93
94
} ) ;
94
- var result = fs . realpathSync ( entry ) ;
95
+ const result = fs . realpathSync ( entry ) ;
95
96
assertEqualPath ( result , path . resolve ( expected ) ) ;
96
97
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
97
98
assertEqualPath ( result , path . resolve ( expected ) ) ;
@@ -103,7 +104,7 @@ function test_simple_absolute_symlink(callback) {
103
104
104
105
// this one should still run, even if skipSymlinks is set,
105
106
// because it uses a junction.
106
- var type = skipSymlinks ? 'junction' : 'dir' ;
107
+ const type = skipSymlinks ? 'junction' : 'dir' ;
107
108
108
109
console . log ( 'using type=%s' , type ) ;
109
110
@@ -117,7 +118,7 @@ function test_simple_absolute_symlink(callback) {
117
118
fs . symlinkSync ( t [ 1 ] , t [ 0 ] , type ) ;
118
119
unlink . push ( t [ 0 ] ) ;
119
120
} ) ;
120
- var result = fs . realpathSync ( entry ) ;
121
+ const result = fs . realpathSync ( entry ) ;
121
122
assertEqualPath ( result , path . resolve ( expected ) ) ;
122
123
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
123
124
assertEqualPath ( result , path . resolve ( expected ) ) ;
@@ -131,16 +132,17 @@ function test_deep_relative_file_symlink(callback) {
131
132
return runNextTest ( ) ;
132
133
}
133
134
134
- var expected = path . join ( common . fixturesDir , 'cycles' , 'root.js' ) ;
135
- var linkData1 = path . relative ( path . join ( targetsAbsDir , 'nested-index' , 'one' ) ,
136
- expected ) ;
137
- var linkPath1 = path . join ( targetsAbsDir ,
135
+ const expected = path . join ( common . fixturesDir , 'cycles' , 'root.js' ) ;
136
+ const linkData1 = path
137
+ . relative ( path . join ( targetsAbsDir , 'nested-index' , 'one' ) ,
138
+ expected ) ;
139
+ const linkPath1 = path . join ( targetsAbsDir ,
138
140
'nested-index' , 'one' , 'symlink1.js' ) ;
139
141
try { fs . unlinkSync ( linkPath1 ) ; } catch ( e ) { }
140
142
fs . symlinkSync ( linkData1 , linkPath1 , 'file' ) ;
141
143
142
- var linkData2 = '../one/symlink1.js' ;
143
- var entry = path . join ( targetsAbsDir ,
144
+ const linkData2 = '../one/symlink1.js' ;
145
+ const entry = path . join ( targetsAbsDir ,
144
146
'nested-index' , 'two' , 'symlink1-b.js' ) ;
145
147
try { fs . unlinkSync ( entry ) ; } catch ( e ) { }
146
148
fs . symlinkSync ( linkData2 , entry , 'file' ) ;
@@ -159,15 +161,15 @@ function test_deep_relative_dir_symlink(callback) {
159
161
common . skip ( 'symlink test (no privs)' ) ;
160
162
return runNextTest ( ) ;
161
163
}
162
- var expected = path . join ( common . fixturesDir , 'cycles' , 'folder' ) ;
163
- var path1b = path . join ( targetsAbsDir , 'nested-index' , 'one' ) ;
164
- var linkPath1b = path . join ( path1b , 'symlink1-dir' ) ;
165
- var linkData1b = path . relative ( path1b , expected ) ;
164
+ const expected = path . join ( common . fixturesDir , 'cycles' , 'folder' ) ;
165
+ const path1b = path . join ( targetsAbsDir , 'nested-index' , 'one' ) ;
166
+ const linkPath1b = path . join ( path1b , 'symlink1-dir' ) ;
167
+ const linkData1b = path . relative ( path1b , expected ) ;
166
168
try { fs . unlinkSync ( linkPath1b ) ; } catch ( e ) { }
167
169
fs . symlinkSync ( linkData1b , linkPath1b , 'dir' ) ;
168
170
169
- var linkData2b = '../one/symlink1-dir' ;
170
- var entry = path . join ( targetsAbsDir ,
171
+ const linkData2b = '../one/symlink1-dir' ;
172
+ const entry = path . join ( targetsAbsDir ,
171
173
'nested-index' , 'two' , 'symlink12-dir' ) ;
172
174
try { fs . unlinkSync ( entry ) ; } catch ( e ) { }
173
175
fs . symlinkSync ( linkData2b , entry , 'dir' ) ;
@@ -187,7 +189,7 @@ function test_cyclic_link_protection(callback) {
187
189
common . skip ( 'symlink test (no privs)' ) ;
188
190
return runNextTest ( ) ;
189
191
}
190
- var entry = common . tmpDir + '/cycles/realpath-3a' ;
192
+ const entry = common . tmpDir + '/cycles/realpath-3a' ;
191
193
[
192
194
[ entry , '../cycles/realpath-3b' ] ,
193
195
[ common . tmpDir + '/cycles/realpath-3b' , '../cycles/realpath-3c' ] ,
@@ -210,10 +212,10 @@ function test_cyclic_link_overprotection(callback) {
210
212
common . skip ( 'symlink test (no privs)' ) ;
211
213
return runNextTest ( ) ;
212
214
}
213
- var cycles = common . tmpDir + '/cycles' ;
214
- var expected = fs . realpathSync ( cycles ) ;
215
- var folder = cycles + '/folder' ;
216
- var link = folder + '/cycles' ;
215
+ const cycles = common . tmpDir + '/cycles' ;
216
+ const expected = fs . realpathSync ( cycles ) ;
217
+ const folder = cycles + '/folder' ;
218
+ const link = folder + '/cycles' ;
217
219
var testPath = cycles ;
218
220
testPath += '/folder/cycles' . repeat ( 10 ) ;
219
221
try { fs . unlinkSync ( link ) ; } catch ( ex ) { }
@@ -233,26 +235,26 @@ function test_relative_input_cwd(callback) {
233
235
}
234
236
235
237
// we need to calculate the relative path to the tmp dir from cwd
236
- var entrydir = process . cwd ( ) ;
237
- var entry = path . relative ( entrydir ,
238
+ const entrydir = process . cwd ( ) ;
239
+ const entry = path . relative ( entrydir ,
238
240
path . join ( common . tmpDir + '/cycles/realpath-3a' ) ) ;
239
- var expected = common . tmpDir + '/cycles/root.js' ;
241
+ const expected = common . tmpDir + '/cycles/root.js' ;
240
242
[
241
243
[ entry , '../cycles/realpath-3b' ] ,
242
244
[ common . tmpDir + '/cycles/realpath-3b' , '../cycles/realpath-3c' ] ,
243
245
[ common . tmpDir + '/cycles/realpath-3c' , 'root.js' ]
244
246
] . forEach ( function ( t ) {
245
- var fn = t [ 0 ] ;
247
+ const fn = t [ 0 ] ;
246
248
console . error ( 'fn=%j' , fn ) ;
247
249
try { fs . unlinkSync ( fn ) ; } catch ( e ) { }
248
- var b = path . basename ( t [ 1 ] ) ;
249
- var type = ( b === 'root.js' ? 'file' : 'dir' ) ;
250
+ const b = path . basename ( t [ 1 ] ) ;
251
+ const type = ( b === 'root.js' ? 'file' : 'dir' ) ;
250
252
console . log ( 'fs.symlinkSync(%j, %j, %j)' , t [ 1 ] , fn , type ) ;
251
253
fs . symlinkSync ( t [ 1 ] , fn , 'file' ) ;
252
254
unlink . push ( fn ) ;
253
255
} ) ;
254
256
255
- var origcwd = process . cwd ( ) ;
257
+ const origcwd = process . cwd ( ) ;
256
258
process . chdir ( entrydir ) ;
257
259
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
258
260
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
@@ -282,7 +284,7 @@ function test_deep_symlink_mix(callback) {
282
284
$tmpDir/targets/nested-index/two/realpath-c -> $tmpDir/cycles/root.js
283
285
$tmpDir/targets/cycles/root.js (hard)
284
286
*/
285
- var entry = tmp ( 'node-test-realpath-f1' ) ;
287
+ const entry = tmp ( 'node-test-realpath-f1' ) ;
286
288
try { fs . unlinkSync ( tmp ( 'node-test-realpath-d2/foo' ) ) ; } catch ( e ) { }
287
289
try { fs . rmdirSync ( tmp ( 'node-test-realpath-d2' ) ) ; } catch ( e ) { }
288
290
fs . mkdirSync ( tmp ( 'node-test-realpath-d2' ) , 0o700 ) ;
@@ -306,7 +308,7 @@ function test_deep_symlink_mix(callback) {
306
308
} finally {
307
309
unlink . push ( tmp ( 'node-test-realpath-d2' ) ) ;
308
310
}
309
- var expected = tmpAbsDir + '/cycles/root.js' ;
311
+ const expected = tmpAbsDir + '/cycles/root.js' ;
310
312
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
311
313
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
312
314
assertEqualPath ( result , path . resolve ( expected ) ) ;
@@ -316,10 +318,10 @@ function test_deep_symlink_mix(callback) {
316
318
317
319
function test_non_symlinks ( callback ) {
318
320
console . log ( 'test_non_symlinks' ) ;
319
- var entrydir = path . dirname ( tmpAbsDir ) ;
320
- var entry = tmpAbsDir . substr ( entrydir . length + 1 ) + '/cycles/root.js' ;
321
- var expected = tmpAbsDir + '/cycles/root.js' ;
322
- var origcwd = process . cwd ( ) ;
321
+ const entrydir = path . dirname ( tmpAbsDir ) ;
322
+ const entry = tmpAbsDir . substr ( entrydir . length + 1 ) + '/cycles/root.js' ;
323
+ const expected = tmpAbsDir + '/cycles/root.js' ;
324
+ const origcwd = process . cwd ( ) ;
323
325
process . chdir ( entrydir ) ;
324
326
assertEqualPath ( fs . realpathSync ( entry ) , path . resolve ( expected ) ) ;
325
327
asynctest ( fs . realpath , [ entry ] , callback , function ( err , result ) {
@@ -329,7 +331,7 @@ function test_non_symlinks(callback) {
329
331
} ) ;
330
332
}
331
333
332
- var upone = path . join ( process . cwd ( ) , '..' ) ;
334
+ const upone = path . join ( process . cwd ( ) , '..' ) ;
333
335
function test_escape_cwd ( cb ) {
334
336
console . log ( 'test_escape_cwd' ) ;
335
337
asynctest ( fs . realpath , [ '..' ] , cb , function ( er , uponeActual ) {
@@ -338,7 +340,7 @@ function test_escape_cwd(cb) {
338
340
' actual:' + uponeActual ) ;
339
341
} ) ;
340
342
}
341
- var uponeActual = fs . realpathSync ( '..' ) ;
343
+ const uponeActual = fs . realpathSync ( '..' ) ;
342
344
assertEqualPath ( upone , uponeActual ,
343
345
'realpathSync("..") expected: ' + path . resolve ( upone ) +
344
346
' actual:' + uponeActual ) ;
@@ -375,11 +377,11 @@ function test_up_multiple(cb) {
375
377
fs . symlinkSync ( '..' , tmp ( 'a/b/e' ) , 'dir' ) ;
376
378
unlink . push ( tmp ( 'a/b/e' ) ) ;
377
379
378
- var abedabed = tmp ( 'abedabed' . split ( '' ) . join ( '/' ) ) ;
379
- var abedabed_real = tmp ( '' ) ;
380
+ const abedabed = tmp ( 'abedabed' . split ( '' ) . join ( '/' ) ) ;
381
+ const abedabed_real = tmp ( '' ) ;
380
382
381
- var abedabeda = tmp ( 'abedabeda' . split ( '' ) . join ( '/' ) ) ;
382
- var abedabeda_real = tmp ( 'a' ) ;
383
+ const abedabeda = tmp ( 'abedabeda' . split ( '' ) . join ( '/' ) ) ;
384
+ const abedabeda_real = tmp ( 'a' ) ;
383
385
384
386
assertEqualPath ( fs . realpathSync ( abedabeda ) , abedabeda_real ) ;
385
387
assertEqualPath ( fs . realpathSync ( abedabed ) , abedabed_real ) ;
@@ -409,11 +411,11 @@ function test_abs_with_kids(cb) {
409
411
410
412
// this one should still run, even if skipSymlinks is set,
411
413
// because it uses a junction.
412
- var type = skipSymlinks ? 'junction' : 'dir' ;
414
+ const type = skipSymlinks ? 'junction' : 'dir' ;
413
415
414
416
console . log ( 'using type=%s' , type ) ;
415
417
416
- var root = tmpAbsDir + '/node-test-realpath-abs-kids' ;
418
+ const root = tmpAbsDir + '/node-test-realpath-abs-kids' ;
417
419
function cleanup ( ) {
418
420
[ '/a/b/c/x.txt' ,
419
421
'/a/link'
@@ -442,9 +444,9 @@ function test_abs_with_kids(cb) {
442
444
fs . symlinkSync ( root + '/a/b' , root + '/a/link' , type ) ;
443
445
}
444
446
setup ( ) ;
445
- var linkPath = root + '/a/link/c/x.txt' ;
446
- var expectPath = root + '/a/b/c/x.txt' ;
447
- var actual = fs . realpathSync ( linkPath ) ;
447
+ const linkPath = root + '/a/link/c/x.txt' ;
448
+ const expectPath = root + '/a/b/c/x.txt' ;
449
+ const actual = fs . realpathSync ( linkPath ) ;
448
450
// console.log({link:linkPath,expect:expectPath,actual:actual},'sync');
449
451
assertEqualPath ( actual , path . resolve ( expectPath ) ) ;
450
452
asynctest ( fs . realpath , [ linkPath ] , cb , function ( er , actual ) {
@@ -456,7 +458,7 @@ function test_abs_with_kids(cb) {
456
458
457
459
// ----------------------------------------------------------------------------
458
460
459
- var tests = [
461
+ const tests = [
460
462
test_simple_error_callback ,
461
463
test_simple_relative_symlink ,
462
464
test_simple_absolute_symlink ,
@@ -471,11 +473,11 @@ var tests = [
471
473
test_abs_with_kids ,
472
474
test_up_multiple
473
475
] ;
474
- var numtests = tests . length ;
476
+ const numtests = tests . length ;
475
477
var testsRun = 0 ;
476
478
function runNextTest ( err ) {
477
479
if ( err ) throw err ;
478
- var test = tests . shift ( ) ;
480
+ const test = tests . shift ( ) ;
479
481
if ( ! test ) {
480
482
return console . log ( numtests +
481
483
' subtests completed OK for fs.realpath' ) ;
@@ -487,13 +489,13 @@ function runNextTest(err) {
487
489
488
490
assertEqualPath ( root , fs . realpathSync ( '/' ) ) ;
489
491
fs . realpath ( '/' , function ( err , result ) {
490
- assert . equal ( null , err ) ;
492
+ assert . ifError ( err ) ;
491
493
assertEqualPath ( root , result ) ;
492
494
} ) ;
493
495
494
496
495
497
function runTest ( ) {
496
- var tmpDirs = [ 'cycles' , 'cycles/folder' ] ;
498
+ const tmpDirs = [ 'cycles' , 'cycles/folder' ] ;
497
499
tmpDirs . forEach ( function ( t ) {
498
500
t = tmp ( t ) ;
499
501
fs . mkdirSync ( t , 0o700 ) ;
@@ -506,6 +508,5 @@ function runTest() {
506
508
507
509
process . on ( 'exit' , function ( ) {
508
510
assert . equal ( numtests , testsRun ) ;
509
- unlink . forEach ( function ( path ) { try { fs . unlinkSync ( path ) ; } catch ( e ) { } } ) ;
510
511
assert . equal ( async_completed , async_expected ) ;
511
512
} ) ;
0 commit comments