summaryrefslogtreecommitdiff
path: root/lib/internal/fs/watchers.js
diff options
context:
space:
mode:
authorZYSzys <zyszys98@gmail.com>2019-05-12 20:30:29 +0800
committerRich Trott <rtrott@gmail.com>2019-05-14 15:13:48 -0700
commit23ef3e4cfb8da65b205e6895947375e5284bebdc (patch)
tree41f5465e41fbabd16c82bc3fc44b566a427e823c /lib/internal/fs/watchers.js
parent4a18b87a3ff7e22625c049f28c4b9b413eb3e450 (diff)
downloadandroid-node-v8-23ef3e4cfb8da65b205e6895947375e5284bebdc.tar.gz
android-node-v8-23ef3e4cfb8da65b205e6895947375e5284bebdc.tar.bz2
android-node-v8-23ef3e4cfb8da65b205e6895947375e5284bebdc.zip
fs: extract path conversion and validation to getValidatedPath
Almost all path validations within our file system are combined with: ```js path = toPathIfFileURL(path); validatePath(path); ``` So simply extracted them out into `getValidatedPath` function to `internal/fs/utils.js` to DRY up the code and reduce duplicating them. PR-URL: https://github.com/nodejs/node/pull/27656 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'lib/internal/fs/watchers.js')
-rw-r--r--lib/internal/fs/watchers.js9
1 files changed, 3 insertions, 6 deletions
diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js
index d29ed90258..bde07cfdc5 100644
--- a/lib/internal/fs/watchers.js
+++ b/lib/internal/fs/watchers.js
@@ -12,7 +12,7 @@ const { UV_ENOSPC } = internalBinding('uv');
const { EventEmitter } = require('events');
const {
getStatsFromBinding,
- validatePath
+ getValidatedPath
} = require('internal/fs/utils');
const {
defaultTriggerAsyncIdScope,
@@ -20,7 +20,6 @@ const {
} = require('internal/async_hooks');
const { toNamespacedPath } = require('path');
const { validateUint32 } = require('internal/validators');
-const { toPathIfFileURL } = require('internal/url');
const assert = require('internal/assert');
const kOldStatus = Symbol('kOldStatus');
@@ -73,8 +72,7 @@ StatWatcher.prototype.start = function(filename, persistent, interval) {
// the sake of backwards compatibility
this[kOldStatus] = -1;
- filename = toPathIfFileURL(filename);
- validatePath(filename, 'filename');
+ filename = getValidatedPath(filename, 'filename');
validateUint32(interval, 'interval');
const err = this._handle.start(toNamespacedPath(filename), interval);
if (err) {
@@ -157,8 +155,7 @@ FSWatcher.prototype.start = function(filename,
return;
}
- filename = toPathIfFileURL(filename);
- validatePath(filename, 'filename');
+ filename = getValidatedPath(filename, 'filename');
const err = this._handle.start(toNamespacedPath(filename),
persistent,