-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: restore JS implementation of realpath
This reverts parts of b488b19 restoring javascript implementation of realpath and realpathSync. Fixes: #7175 Fixes: #6861 Fixes: #7294 Fixes: #7192 Fixes: #7044 Fixes: #6624 Fixes: #6978 PR-URL: #7899 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
Showing
4 changed files
with
360 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
})); |
Oops, something went wrong.