aboutsummaryrefslogtreecommitdiff
path: root/lib/internal/fs
diff options
context:
space:
mode:
authorguybedford <guybedford@gmail.com>2018-08-24 18:13:32 +0200
committerguybedford <guybedford@gmail.com>2018-09-04 16:08:21 +0200
commiteef072fa083f05f84fa6ca1908472eb228095a38 (patch)
tree3fd3bc972b893bd49616bba2808e449743f55ee9 /lib/internal/fs
parent0d3da39f575afba5ab6a5a34f4e88a798a66dc6d (diff)
downloadandroid-node-v8-eef072fa083f05f84fa6ca1908472eb228095a38.tar.gz
android-node-v8-eef072fa083f05f84fa6ca1908472eb228095a38.tar.bz2
android-node-v8-eef072fa083f05f84fa6ca1908472eb228095a38.zip
url: provide pathToFileURL and fileURLToPath
PR-URL: https://github.com/nodejs/node/pull/22506 Reviewed-By: John-David Dalton <john.david.dalton@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Gus Caplan <me@gus.host>
Diffstat (limited to 'lib/internal/fs')
-rw-r--r--lib/internal/fs/promises.js46
-rw-r--r--lib/internal/fs/streams.js6
-rw-r--r--lib/internal/fs/watchers.js6
3 files changed, 29 insertions, 29 deletions
diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js
index e0ddee4c7f..0aa26ba2f9 100644
--- a/lib/internal/fs/promises.js
+++ b/lib/internal/fs/promises.js
@@ -15,7 +15,7 @@ const {
ERR_INVALID_ARG_VALUE,
ERR_METHOD_NOT_IMPLEMENTED
} = require('internal/errors').codes;
-const { getPathFromURL } = require('internal/url');
+const { toPathIfFileURL } = require('internal/url');
const { isUint8Array } = require('internal/util/types');
const {
copyObject,
@@ -172,7 +172,7 @@ async function readFileHandle(filehandle, options) {
// All of the functions are defined as async in order to ensure that errors
// thrown cause promise rejections rather than being thrown synchronously.
async function access(path, mode = F_OK) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
mode = mode | 0;
@@ -181,8 +181,8 @@ async function access(path, mode = F_OK) {
}
async function copyFile(src, dest, flags) {
- src = getPathFromURL(src);
- dest = getPathFromURL(dest);
+ src = toPathIfFileURL(src);
+ dest = toPathIfFileURL(dest);
validatePath(src, 'src');
validatePath(dest, 'dest');
flags = flags | 0;
@@ -194,7 +194,7 @@ async function copyFile(src, dest, flags) {
// Note that unlike fs.open() which uses numeric file descriptors,
// fsPromises.open() uses the fs.FileHandle class.
async function open(path, flags, mode) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
mode = validateMode(mode, 'mode', 0o666);
return new FileHandle(
@@ -257,8 +257,8 @@ async function write(handle, buffer, offset, length, position) {
}
async function rename(oldPath, newPath) {
- oldPath = getPathFromURL(oldPath);
- newPath = getPathFromURL(newPath);
+ oldPath = toPathIfFileURL(oldPath);
+ newPath = toPathIfFileURL(newPath);
validatePath(oldPath, 'oldPath');
validatePath(newPath, 'newPath');
return binding.rename(pathModule.toNamespacedPath(oldPath),
@@ -278,7 +278,7 @@ async function ftruncate(handle, len = 0) {
}
async function rmdir(path) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
return binding.rmdir(pathModule.toNamespacedPath(path), kUsePromises);
}
@@ -301,7 +301,7 @@ async function mkdir(path, options) {
recursive = false,
mode = 0o777
} = options || {};
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
if (typeof recursive !== 'boolean')
@@ -314,7 +314,7 @@ async function mkdir(path, options) {
async function readdir(path, options) {
options = getOptions(options, {});
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
const result = await binding.readdir(pathModule.toNamespacedPath(path),
options.encoding, !!options.withTypes,
@@ -326,7 +326,7 @@ async function readdir(path, options) {
async function readlink(path, options) {
options = getOptions(options, {});
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path, 'oldPath');
return binding.readlink(pathModule.toNamespacedPath(path),
options.encoding, kUsePromises);
@@ -334,8 +334,8 @@ async function readlink(path, options) {
async function symlink(target, path, type_) {
const type = (typeof type_ === 'string' ? type_ : null);
- target = getPathFromURL(target);
- path = getPathFromURL(path);
+ target = toPathIfFileURL(target);
+ path = toPathIfFileURL(path);
validatePath(target, 'target');
validatePath(path);
return binding.symlink(preprocessSymlinkDestination(target, type, path),
@@ -351,7 +351,7 @@ async function fstat(handle, options = { bigint: false }) {
}
async function lstat(path, options = { bigint: false }) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
const result = await binding.lstat(pathModule.toNamespacedPath(path),
options.bigint, kUsePromises);
@@ -359,7 +359,7 @@ async function lstat(path, options = { bigint: false }) {
}
async function stat(path, options = { bigint: false }) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
const result = await binding.stat(pathModule.toNamespacedPath(path),
options.bigint, kUsePromises);
@@ -367,8 +367,8 @@ async function stat(path, options = { bigint: false }) {
}
async function link(existingPath, newPath) {
- existingPath = getPathFromURL(existingPath);
- newPath = getPathFromURL(newPath);
+ existingPath = toPathIfFileURL(existingPath);
+ newPath = toPathIfFileURL(newPath);
validatePath(existingPath, 'existingPath');
validatePath(newPath, 'newPath');
return binding.link(pathModule.toNamespacedPath(existingPath),
@@ -377,7 +377,7 @@ async function link(existingPath, newPath) {
}
async function unlink(path) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
return binding.unlink(pathModule.toNamespacedPath(path), kUsePromises);
}
@@ -389,7 +389,7 @@ async function fchmod(handle, mode) {
}
async function chmod(path, mode) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
mode = validateMode(mode, 'mode');
return binding.chmod(pathModule.toNamespacedPath(path), mode, kUsePromises);
@@ -404,7 +404,7 @@ async function lchmod(path, mode) {
}
async function lchown(path, uid, gid) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
@@ -420,7 +420,7 @@ async function fchown(handle, uid, gid) {
}
async function chown(path, uid, gid) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
validateUint32(uid, 'uid');
validateUint32(gid, 'gid');
@@ -429,7 +429,7 @@ async function chown(path, uid, gid) {
}
async function utimes(path, atime, mtime) {
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
return binding.utimes(pathModule.toNamespacedPath(path),
toUnixTimestamp(atime),
@@ -446,7 +446,7 @@ async function futimes(handle, atime, mtime) {
async function realpath(path, options) {
options = getOptions(options, {});
- path = getPathFromURL(path);
+ path = toPathIfFileURL(path);
validatePath(path);
return binding.realpath(path, options.encoding, kUsePromises);
}
diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js
index 502b3c1430..a2ae1c9787 100644
--- a/lib/internal/fs/streams.js
+++ b/lib/internal/fs/streams.js
@@ -16,7 +16,7 @@ const {
getOptions,
} = require('internal/fs/utils');
const { Readable, Writable } = require('stream');
-const { getPathFromURL } = require('internal/url');
+const { toPathIfFileURL } = require('internal/url');
const util = require('util');
const kMinPoolSpace = 128;
@@ -52,7 +52,7 @@ function ReadStream(path, options) {
Readable.call(this, options);
// path will be ignored when fd is specified, so it can be falsy
- this.path = getPathFromURL(path);
+ this.path = toPathIfFileURL(path);
this.fd = options.fd === undefined ? null : options.fd;
this.flags = options.flags === undefined ? 'r' : options.flags;
this.mode = options.mode === undefined ? 0o666 : options.mode;
@@ -240,7 +240,7 @@ function WriteStream(path, options) {
Writable.call(this, options);
// path will be ignored when fd is specified, so it can be falsy
- this.path = getPathFromURL(path);
+ this.path = toPathIfFileURL(path);
this.fd = options.fd === undefined ? null : options.fd;
this.flags = options.flags === undefined ? 'w' : options.flags;
this.mode = options.mode === undefined ? 0o666 : options.mode;
diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js
index 8f8cb5249b..3db3a5cc7c 100644
--- a/lib/internal/fs/watchers.js
+++ b/lib/internal/fs/watchers.js
@@ -18,7 +18,7 @@ const {
} = require('internal/async_hooks');
const { toNamespacedPath } = require('path');
const { validateUint32 } = require('internal/validators');
-const { getPathFromURL } = require('internal/url');
+const { toPathIfFileURL } = require('internal/url');
const util = require('util');
const assert = require('assert');
@@ -71,7 +71,7 @@ StatWatcher.prototype.start = function(filename, persistent, interval) {
// the sake of backwards compatibility
this[kOldStatus] = -1;
- filename = getPathFromURL(filename);
+ filename = toPathIfFileURL(filename);
validatePath(filename, 'filename');
validateUint32(interval, 'interval');
const err = this._handle.start(toNamespacedPath(filename), interval);
@@ -154,7 +154,7 @@ FSWatcher.prototype.start = function(filename,
return;
}
- filename = getPathFromURL(filename);
+ filename = toPathIfFileURL(filename);
validatePath(filename, 'filename');
const err = this._handle.start(toNamespacedPath(filename),