|
|
@ -29,6 +29,7 @@ let async_completed = 0; |
|
|
|
let async_expected = 0; |
|
|
|
const unlink = []; |
|
|
|
let skipSymlinks = false; |
|
|
|
const tmpDir = common.tmpDir; |
|
|
|
|
|
|
|
common.refreshTmpDir(); |
|
|
|
|
|
|
@ -62,11 +63,11 @@ if (common.isWindows) { |
|
|
|
|
|
|
|
|
|
|
|
function tmp(p) { |
|
|
|
return path.join(common.tmpDir, p); |
|
|
|
return path.join(tmpDir, p); |
|
|
|
} |
|
|
|
|
|
|
|
const targetsAbsDir = path.join(common.tmpDir, 'targets'); |
|
|
|
const tmpAbsDir = common.tmpDir; |
|
|
|
const targetsAbsDir = path.join(tmpDir, 'targets'); |
|
|
|
const tmpAbsDir = tmpDir; |
|
|
|
|
|
|
|
// Set up targetsAbsDir and expected subdirectories
|
|
|
|
fs.mkdirSync(targetsAbsDir); |
|
|
@ -105,10 +106,10 @@ function test_simple_relative_symlink(callback) { |
|
|
|
common.skip('symlink test (no privs)'); |
|
|
|
return runNextTest(); |
|
|
|
} |
|
|
|
const entry = common.tmpDir + '/symlink'; |
|
|
|
const expected = common.tmpDir + '/cycles/root.js'; |
|
|
|
const entry = `${tmpDir}/symlink`; |
|
|
|
const expected = `${tmpDir}/cycles/root.js`; |
|
|
|
[ |
|
|
|
[entry, '../' + common.tmpDirName + '/cycles/root.js'] |
|
|
|
[entry, `../${common.tmpDirName}/cycles/root.js`] |
|
|
|
].forEach(function(t) { |
|
|
|
try { fs.unlinkSync(t[0]); } catch (e) {} |
|
|
|
console.log('fs.symlinkSync(%j, %j, %j)', t[1], t[0], 'file'); |
|
|
@ -131,8 +132,8 @@ function test_simple_absolute_symlink(callback) { |
|
|
|
|
|
|
|
console.log('using type=%s', type); |
|
|
|
|
|
|
|
const entry = tmpAbsDir + '/symlink'; |
|
|
|
const expected = common.fixturesDir + '/nested-index/one'; |
|
|
|
const entry = `${tmpAbsDir}/symlink`; |
|
|
|
const expected = `${common.fixturesDir}/nested-index/one`; |
|
|
|
[ |
|
|
|
[entry, expected] |
|
|
|
].forEach(function(t) { |
|
|
@ -212,11 +213,11 @@ function test_cyclic_link_protection(callback) { |
|
|
|
common.skip('symlink test (no privs)'); |
|
|
|
return runNextTest(); |
|
|
|
} |
|
|
|
const entry = path.join(common.tmpDir, '/cycles/realpath-3a'); |
|
|
|
const entry = path.join(tmpDir, '/cycles/realpath-3a'); |
|
|
|
[ |
|
|
|
[entry, '../cycles/realpath-3b'], |
|
|
|
[path.join(common.tmpDir, '/cycles/realpath-3b'), '../cycles/realpath-3c'], |
|
|
|
[path.join(common.tmpDir, '/cycles/realpath-3c'), '../cycles/realpath-3a'] |
|
|
|
[path.join(tmpDir, '/cycles/realpath-3b'), '../cycles/realpath-3c'], |
|
|
|
[path.join(tmpDir, '/cycles/realpath-3c'), '../cycles/realpath-3a'] |
|
|
|
].forEach(function(t) { |
|
|
|
try { fs.unlinkSync(t[0]); } catch (e) {} |
|
|
|
fs.symlinkSync(t[1], t[0], 'dir'); |
|
|
@ -239,10 +240,10 @@ function test_cyclic_link_overprotection(callback) { |
|
|
|
common.skip('symlink test (no privs)'); |
|
|
|
return runNextTest(); |
|
|
|
} |
|
|
|
const cycles = common.tmpDir + '/cycles'; |
|
|
|
const cycles = `${tmpDir}/cycles`; |
|
|
|
const expected = fs.realpathSync(cycles); |
|
|
|
const folder = cycles + '/folder'; |
|
|
|
const link = folder + '/cycles'; |
|
|
|
const folder = `${cycles}/folder`; |
|
|
|
const link = `${folder}/cycles`; |
|
|
|
let testPath = cycles; |
|
|
|
testPath += '/folder/cycles'.repeat(10); |
|
|
|
try { fs.unlinkSync(link); } catch (ex) {} |
|
|
@ -264,12 +265,12 @@ function test_relative_input_cwd(callback) { |
|
|
|
// we need to calculate the relative path to the tmp dir from cwd
|
|
|
|
const entrydir = process.cwd(); |
|
|
|
const entry = path.relative(entrydir, |
|
|
|
path.join(common.tmpDir + '/cycles/realpath-3a')); |
|
|
|
const expected = common.tmpDir + '/cycles/root.js'; |
|
|
|
path.join(`${tmpDir}/cycles/realpath-3a`)); |
|
|
|
const expected = `${tmpDir}/cycles/root.js`; |
|
|
|
[ |
|
|
|
[entry, '../cycles/realpath-3b'], |
|
|
|
[common.tmpDir + '/cycles/realpath-3b', '../cycles/realpath-3c'], |
|
|
|
[common.tmpDir + '/cycles/realpath-3c', 'root.js'] |
|
|
|
[`${tmpDir}/cycles/realpath-3b`, '../cycles/realpath-3c'], |
|
|
|
[`${tmpDir}/cycles/realpath-3c`, 'root.js'] |
|
|
|
].forEach(function(t) { |
|
|
|
const fn = t[0]; |
|
|
|
console.error('fn=%j', fn); |
|
|
@ -317,16 +318,16 @@ function test_deep_symlink_mix(callback) { |
|
|
|
fs.mkdirSync(tmp('node-test-realpath-d2'), 0o700); |
|
|
|
try { |
|
|
|
[ |
|
|
|
[entry, common.tmpDir + '/node-test-realpath-d1/foo'], |
|
|
|
[entry, `${tmpDir}/node-test-realpath-d1/foo`], |
|
|
|
[tmp('node-test-realpath-d1'), |
|
|
|
common.tmpDir + '/node-test-realpath-d2'], |
|
|
|
`${tmpDir}/node-test-realpath-d2`], |
|
|
|
[tmp('node-test-realpath-d2/foo'), '../node-test-realpath-f2'], |
|
|
|
[tmp('node-test-realpath-f2'), targetsAbsDir + |
|
|
|
'/nested-index/one/realpath-c'], |
|
|
|
[targetsAbsDir + '/nested-index/one/realpath-c', targetsAbsDir + |
|
|
|
'/nested-index/two/realpath-c'], |
|
|
|
[targetsAbsDir + '/nested-index/two/realpath-c', |
|
|
|
common.tmpDir + '/cycles/root.js'] |
|
|
|
[tmp('node-test-realpath-f2'), |
|
|
|
`${targetsAbsDir}/nested-index/one/realpath-c`], |
|
|
|
[`${targetsAbsDir}/nested-index/one/realpath-c`, |
|
|
|
`${targetsAbsDir}/nested-index/two/realpath-c`], |
|
|
|
[`${targetsAbsDir}/nested-index/two/realpath-c`, |
|
|
|
`${tmpDir}/cycles/root.js`] |
|
|
|
].forEach(function(t) { |
|
|
|
try { fs.unlinkSync(t[0]); } catch (e) {} |
|
|
|
fs.symlinkSync(t[1], t[0]); |
|
|
@ -335,7 +336,7 @@ function test_deep_symlink_mix(callback) { |
|
|
|
} finally { |
|
|
|
unlink.push(tmp('node-test-realpath-d2')); |
|
|
|
} |
|
|
|
const expected = tmpAbsDir + '/cycles/root.js'; |
|
|
|
const expected = `${tmpAbsDir}/cycles/root.js`; |
|
|
|
assertEqualPath(fs.realpathSync(entry), path.resolve(expected)); |
|
|
|
asynctest(fs.realpath, [entry], callback, function(err, result) { |
|
|
|
assertEqualPath(result, path.resolve(expected)); |
|
|
@ -346,8 +347,8 @@ function test_deep_symlink_mix(callback) { |
|
|
|
function test_non_symlinks(callback) { |
|
|
|
console.log('test_non_symlinks'); |
|
|
|
const entrydir = path.dirname(tmpAbsDir); |
|
|
|
const entry = tmpAbsDir.substr(entrydir.length + 1) + '/cycles/root.js'; |
|
|
|
const expected = tmpAbsDir + '/cycles/root.js'; |
|
|
|
const entry = `${tmpAbsDir.substr(entrydir.length + 1)}/cycles/root.js`; |
|
|
|
const expected = `${tmpAbsDir}/cycles/root.js`; |
|
|
|
const origcwd = process.cwd(); |
|
|
|
process.chdir(entrydir); |
|
|
|
assertEqualPath(fs.realpathSync(entry), path.resolve(expected)); |
|
|
@ -362,15 +363,15 @@ const upone = path.join(process.cwd(), '..'); |
|
|
|
function test_escape_cwd(cb) { |
|
|
|
console.log('test_escape_cwd'); |
|
|
|
asynctest(fs.realpath, ['..'], cb, function(er, uponeActual) { |
|
|
|
assertEqualPath(upone, uponeActual, |
|
|
|
'realpath("..") expected: ' + path.resolve(upone) + |
|
|
|
' actual:' + uponeActual); |
|
|
|
assertEqualPath( |
|
|
|
upone, uponeActual, |
|
|
|
`realpath("..") expected: ${path.resolve(upone)} actual:${uponeActual}`); |
|
|
|
}); |
|
|
|
} |
|
|
|
const uponeActual = fs.realpathSync('..'); |
|
|
|
assertEqualPath(upone, uponeActual, |
|
|
|
'realpathSync("..") expected: ' + path.resolve(upone) + |
|
|
|
' actual:' + uponeActual); |
|
|
|
assertEqualPath( |
|
|
|
upone, uponeActual, |
|
|
|
`realpathSync("..") expected: ${path.resolve(upone)} actual:${uponeActual}`); |
|
|
|
|
|
|
|
|
|
|
|
// going up with .. multiple times
|
|
|
@ -442,7 +443,7 @@ function test_abs_with_kids(cb) { |
|
|
|
|
|
|
|
console.log('using type=%s', type); |
|
|
|
|
|
|
|
const root = tmpAbsDir + '/node-test-realpath-abs-kids'; |
|
|
|
const root = `${tmpAbsDir}/node-test-realpath-abs-kids`; |
|
|
|
function cleanup() { |
|
|
|
['/a/b/c/x.txt', |
|
|
|
'/a/link' |
|
|
@ -464,15 +465,15 @@ function test_abs_with_kids(cb) { |
|
|
|
'/a/b', |
|
|
|
'/a/b/c' |
|
|
|
].forEach(function(folder) { |
|
|
|
console.log('mkdir ' + root + folder); |
|
|
|
console.log(`mkdir ${root}${folder}`); |
|
|
|
fs.mkdirSync(root + folder, 0o700); |
|
|
|
}); |
|
|
|
fs.writeFileSync(root + '/a/b/c/x.txt', 'foo'); |
|
|
|
fs.symlinkSync(root + '/a/b', root + '/a/link', type); |
|
|
|
fs.writeFileSync(`${root}/a/b/c/x.txt`, 'foo'); |
|
|
|
fs.symlinkSync(`${root}/a/b`, `${root}/a/link`, type); |
|
|
|
} |
|
|
|
setup(); |
|
|
|
const linkPath = root + '/a/link/c/x.txt'; |
|
|
|
const expectPath = root + '/a/b/c/x.txt'; |
|
|
|
const linkPath = `${root}/a/link/c/x.txt`; |
|
|
|
const expectPath = `${root}/a/b/c/x.txt`; |
|
|
|
const actual = fs.realpathSync(linkPath); |
|
|
|
// console.log({link:linkPath,expect:expectPath,actual:actual},'sync');
|
|
|
|
assertEqualPath(actual, path.resolve(expectPath)); |
|
|
@ -506,8 +507,7 @@ function runNextTest(err) { |
|
|
|
assert.ifError(err); |
|
|
|
const test = tests.shift(); |
|
|
|
if (!test) { |
|
|
|
return console.log(numtests + |
|
|
|
' subtests completed OK for fs.realpath'); |
|
|
|
return console.log(`${numtests} subtests completed OK for fs.realpath`); |
|
|
|
} |
|
|
|
testsRun++; |
|
|
|
test(runNextTest); |
|
|
|