mirror of https://github.com/lukechilds/node.git
Browse Source
This reverts parts of b488b19eaf
restoring javascript implementation of realpath and realpathSync.
Fixes: https://github.com/nodejs/node/issues/7175
Fixes: https://github.com/nodejs/node/issues/6861
Fixes: https://github.com/nodejs/node/issues/7294
Fixes: https://github.com/nodejs/node/issues/7192
Fixes: https://github.com/nodejs/node/issues/7044
Fixes: https://github.com/nodejs/node/issues/6624
Fixes: https://github.com/nodejs/node/issues/6978
PR-URL: https://github.com/nodejs/node/pull/7899
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
v7.x
4 changed files with 360 additions and 14 deletions
@ -0,0 +1,88 @@ |
|||||
|
'use strict'; |
||||
|
const common = require('../common'); |
||||
|
const assert = require('assert'); |
||||
|
const fs = require('fs'); |
||||
|
|
||||
|
const string_dir = fs.realpathSync(common.fixturesDir); |
||||
|
const buffer_dir = Buffer.from(string_dir); |
||||
|
|
||||
|
const encodings = ['ascii', 'utf8', 'utf16le', 'ucs2', |
||||
|
'base64', 'binary', 'hex']; |
||||
|
var expected = {}; |
||||
|
encodings.forEach((encoding) => { |
||||
|
expected[encoding] = buffer_dir.toString(encoding); |
||||
|
}); |
||||
|
|
||||
|
|
||||
|
// test sync version
|
||||
|
for (var encoding in expected) { |
||||
|
const expected_value = expected[encoding]; |
||||
|
let result; |
||||
|
|
||||
|
result = fs.realpathSync(string_dir, {encoding: encoding}); |
||||
|
assert.strictEqual(result, expected_value); |
||||
|
|
||||
|
result = fs.realpathSync(string_dir, encoding); |
||||
|
assert.strictEqual(result, expected_value); |
||||
|
|
||||
|
result = fs.realpathSync(buffer_dir, {encoding: encoding}); |
||||
|
assert.strictEqual(result, expected_value); |
||||
|
|
||||
|
result = fs.realpathSync(buffer_dir, encoding); |
||||
|
assert.strictEqual(result, expected_value); |
||||
|
} |
||||
|
|
||||
|
let buffer_result; |
||||
|
buffer_result = fs.realpathSync(string_dir, {encoding: 'buffer'}); |
||||
|
assert.deepStrictEqual(buffer_result, buffer_dir); |
||||
|
|
||||
|
buffer_result = fs.realpathSync(string_dir, 'buffer'); |
||||
|
assert.deepStrictEqual(buffer_result, buffer_dir); |
||||
|
|
||||
|
buffer_result = fs.realpathSync(buffer_dir, {encoding: 'buffer'}); |
||||
|
assert.deepStrictEqual(buffer_result, buffer_dir); |
||||
|
|
||||
|
buffer_result = fs.realpathSync(buffer_dir, 'buffer'); |
||||
|
assert.deepStrictEqual(buffer_result, buffer_dir); |
||||
|
|
||||
|
// test async version
|
||||
|
for (encoding in expected) { |
||||
|
const expected_value = expected[encoding]; |
||||
|
|
||||
|
fs.realpath(string_dir, {encoding: encoding}, common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.strictEqual(res, expected_value); |
||||
|
})); |
||||
|
fs.realpath(string_dir, encoding, common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.strictEqual(res, expected_value); |
||||
|
})); |
||||
|
fs.realpath(buffer_dir, {encoding: encoding}, common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.strictEqual(res, expected_value); |
||||
|
})); |
||||
|
fs.realpath(buffer_dir, encoding, common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.strictEqual(res, expected_value); |
||||
|
})); |
||||
|
} |
||||
|
|
||||
|
fs.realpath(string_dir, {encoding: 'buffer'}, common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.deepStrictEqual(res, buffer_dir); |
||||
|
})); |
||||
|
|
||||
|
fs.realpath(string_dir, 'buffer', common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.deepStrictEqual(res, buffer_dir); |
||||
|
})); |
||||
|
|
||||
|
fs.realpath(buffer_dir, {encoding: 'buffer'}, common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.deepStrictEqual(res, buffer_dir); |
||||
|
})); |
||||
|
|
||||
|
fs.realpath(buffer_dir, 'buffer', common.mustCall((err, res) => { |
||||
|
assert(!err); |
||||
|
assert.deepStrictEqual(res, buffer_dir); |
||||
|
})); |
@ -0,0 +1,53 @@ |
|||||
|
'use strict'; |
||||
|
|
||||
|
const common = require('../common'); |
||||
|
const assert = require('assert'); |
||||
|
const fs = require('fs'); |
||||
|
const spawnSync = require('child_process').spawnSync; |
||||
|
|
||||
|
if (!common.isWindows) { |
||||
|
common.skip('Test for Windows only'); |
||||
|
return; |
||||
|
} |
||||
|
let result; |
||||
|
|
||||
|
// create a subst drive
|
||||
|
const driveLetters = 'ABCDEFGHIJKLMNOPQRSTUWXYZ'; |
||||
|
let drive; |
||||
|
for (var i = 0; i < driveLetters.length; ++i) { |
||||
|
drive = `${driveLetters[i]}:`; |
||||
|
result = spawnSync('subst', [drive, common.fixturesDir]); |
||||
|
if (result.status === 0) |
||||
|
break; |
||||
|
} |
||||
|
if (i === driveLetters.length) { |
||||
|
common.skip('Cannot create subst drive'); |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
// schedule cleanup (and check if all callbacks where called)
|
||||
|
process.on('exit', function() { |
||||
|
spawnSync('subst', ['/d', drive]); |
||||
|
}); |
||||
|
|
||||
|
// test:
|
||||
|
const filename = `${drive}\\empty.js`; |
||||
|
const filenameBuffer = Buffer.from(filename); |
||||
|
|
||||
|
result = fs.realpathSync(filename); |
||||
|
assert.strictEqual(result, filename); |
||||
|
|
||||
|
result = fs.realpathSync(filename, 'buffer'); |
||||
|
assert(Buffer.isBuffer(result)); |
||||
|
assert(result.equals(filenameBuffer)); |
||||
|
|
||||
|
fs.realpath(filename, common.mustCall(function(err, result) { |
||||
|
assert(!err); |
||||
|
assert.strictEqual(result, filename); |
||||
|
})); |
||||
|
|
||||
|
fs.realpath(filename, 'buffer', common.mustCall(function(err, result) { |
||||
|
assert(!err); |
||||
|
assert(Buffer.isBuffer(result)); |
||||
|
assert(result.equals(filenameBuffer)); |
||||
|
})); |
Loading…
Reference in new issue