NUEVA BUSQUEDA DE DATOS SRI
This commit is contained in:
77
node_modules/readdirp/index.js
generated
vendored
77
node_modules/readdirp/index.js
generated
vendored
@@ -9,6 +9,7 @@ const picomatch = require('picomatch');
|
||||
const readdir = promisify(fs.readdir);
|
||||
const stat = promisify(fs.stat);
|
||||
const lstat = promisify(fs.lstat);
|
||||
const realpath = promisify(fs.realpath);
|
||||
|
||||
/**
|
||||
* @typedef {Object} EntryInfo
|
||||
@@ -20,7 +21,8 @@ const lstat = promisify(fs.lstat);
|
||||
*/
|
||||
|
||||
const BANG = '!';
|
||||
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP']);
|
||||
const RECURSIVE_ERROR_CODE = 'READDIRP_RECURSIVE_ERROR';
|
||||
const NORMAL_FLOW_ERRORS = new Set(['ENOENT', 'EPERM', 'EACCES', 'ELOOP', RECURSIVE_ERROR_CODE]);
|
||||
const FILE_TYPE = 'files';
|
||||
const DIR_TYPE = 'directories';
|
||||
const FILE_DIR_TYPE = 'files_directories';
|
||||
@@ -28,6 +30,8 @@ const EVERYTHING_TYPE = 'all';
|
||||
const ALL_TYPES = [FILE_TYPE, DIR_TYPE, FILE_DIR_TYPE, EVERYTHING_TYPE];
|
||||
|
||||
const isNormalFlowError = error => NORMAL_FLOW_ERRORS.has(error.code);
|
||||
const [maj, min] = process.versions.node.split('.').slice(0, 2).map(n => Number.parseInt(n, 10));
|
||||
const wantBigintFsStats = process.platform === 'win32' && (maj > 10 || (maj === 10 && min >= 5));
|
||||
|
||||
const normalizeFilter = filter => {
|
||||
if (filter === undefined) return;
|
||||
@@ -90,7 +94,7 @@ class ReaddirpStream extends Readable {
|
||||
|
||||
const statMethod = opts.lstat ? lstat : stat;
|
||||
// Use bigint stats if it's windows and stat() supports options (node 10+).
|
||||
if (process.platform === 'win32' && stat.length === 3) {
|
||||
if (wantBigintFsStats) {
|
||||
this._stat = path => statMethod(path, { bigint: true });
|
||||
} else {
|
||||
this._stat = statMethod;
|
||||
@@ -106,11 +110,7 @@ class ReaddirpStream extends Readable {
|
||||
this._rdOptions = { encoding: 'utf8', withFileTypes: this._isDirent };
|
||||
|
||||
// Launch stream with one parent, the root dir.
|
||||
try {
|
||||
this.parents = [this._exploreDir(root, 1)];
|
||||
} catch (error) {
|
||||
this.destroy(error);
|
||||
}
|
||||
this.parents = [this._exploreDir(root, 1)];
|
||||
this.reading = false;
|
||||
this.parent = undefined;
|
||||
}
|
||||
@@ -126,7 +126,10 @@ class ReaddirpStream extends Readable {
|
||||
if (files.length > 0) {
|
||||
const slice = files.splice(0, batch).map(dirent => this._formatEntry(dirent, path));
|
||||
for (const entry of await Promise.all(slice)) {
|
||||
if (this._isDirAndMatchesFilter(entry)) {
|
||||
if (this.destroyed) return;
|
||||
|
||||
const entryType = await this._getEntryType(entry);
|
||||
if (entryType === 'directory' && this._directoryFilter(entry)) {
|
||||
if (depth <= this._maxDepth) {
|
||||
this.parents.push(this._exploreDir(entry.fullPath, depth + 1));
|
||||
}
|
||||
@@ -135,7 +138,7 @@ class ReaddirpStream extends Readable {
|
||||
this.push(entry);
|
||||
batch--;
|
||||
}
|
||||
} else if (this._isFileAndMatchesFilter(entry)) {
|
||||
} else if ((entryType === 'file' || this._includeAsFile(entry)) && this._fileFilter(entry)) {
|
||||
if (this._wantsFile) {
|
||||
this.push(entry);
|
||||
batch--;
|
||||
@@ -149,6 +152,7 @@ class ReaddirpStream extends Readable {
|
||||
break;
|
||||
}
|
||||
this.parent = await parent;
|
||||
if (this.destroyed) return;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -165,14 +169,15 @@ class ReaddirpStream extends Readable {
|
||||
} catch (error) {
|
||||
this._onError(error);
|
||||
}
|
||||
return {files, depth, path};
|
||||
return { files, depth, path };
|
||||
}
|
||||
|
||||
async _formatEntry(dirent, path) {
|
||||
const basename = this._isDirent ? dirent.name : dirent;
|
||||
const fullPath = sysPath.resolve(sysPath.join(path, basename));
|
||||
const entry = {path: sysPath.relative(this._root, fullPath), fullPath, basename};
|
||||
let entry;
|
||||
try {
|
||||
const basename = this._isDirent ? dirent.name : dirent;
|
||||
const fullPath = sysPath.resolve(sysPath.join(path, basename));
|
||||
entry = { path: sysPath.relative(this._root, fullPath), fullPath, basename };
|
||||
entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
|
||||
} catch (err) {
|
||||
this._onError(err);
|
||||
@@ -184,24 +189,52 @@ class ReaddirpStream extends Readable {
|
||||
if (isNormalFlowError(err) && !this.destroyed) {
|
||||
this.emit('warn', err);
|
||||
} else {
|
||||
throw err;
|
||||
this.destroy(err);
|
||||
}
|
||||
}
|
||||
|
||||
_isDirAndMatchesFilter(entry) {
|
||||
async _getEntryType(entry) {
|
||||
// entry may be undefined, because a warning or an error were emitted
|
||||
// and the statsProp is undefined
|
||||
const stats = entry && entry[this._statsProp];
|
||||
return stats && stats.isDirectory() && this._directoryFilter(entry);
|
||||
if (!stats) {
|
||||
return;
|
||||
}
|
||||
if (stats.isFile()) {
|
||||
return 'file';
|
||||
}
|
||||
if (stats.isDirectory()) {
|
||||
return 'directory';
|
||||
}
|
||||
if (stats && stats.isSymbolicLink()) {
|
||||
const full = entry.fullPath;
|
||||
try {
|
||||
const entryRealPath = await realpath(full);
|
||||
const entryRealPathStats = await lstat(entryRealPath);
|
||||
if (entryRealPathStats.isFile()) {
|
||||
return 'file';
|
||||
}
|
||||
if (entryRealPathStats.isDirectory()) {
|
||||
const len = entryRealPath.length;
|
||||
if (full.startsWith(entryRealPath) && full.substr(len, 1) === sysPath.sep) {
|
||||
const recursiveError = new Error(
|
||||
`Circular symlink detected: "${full}" points to "${entryRealPath}"`
|
||||
);
|
||||
recursiveError.code = RECURSIVE_ERROR_CODE;
|
||||
return this._onError(recursiveError);
|
||||
}
|
||||
return 'directory';
|
||||
}
|
||||
} catch (error) {
|
||||
this._onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_isFileAndMatchesFilter(entry) {
|
||||
_includeAsFile(entry) {
|
||||
const stats = entry && entry[this._statsProp];
|
||||
const isFileType = stats && (
|
||||
(this._wantsEverything && !stats.isDirectory()) ||
|
||||
(stats.isFile() || stats.isSymbolicLink())
|
||||
);
|
||||
return isFileType && this._fileFilter(entry);
|
||||
|
||||
return stats && this._wantsEverything && !stats.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user