NUEVA BUSQUEDA DE DATOS SRI

This commit is contained in:
2023-04-11 10:50:28 -05:00
parent d9d7eb83cb
commit 6b4b3e263c
612 changed files with 11604 additions and 36692 deletions

View File

@@ -2,6 +2,7 @@
const {sep} = require('path');
const {platform} = process;
const os = require('os');
exports.EV_ALL = 'all';
exports.EV_READY = 'ready';
@@ -23,6 +24,7 @@ exports.FSEVENT_DELETED = 'deleted';
exports.FSEVENT_MOVED = 'moved';
exports.FSEVENT_CLONED = 'cloned';
exports.FSEVENT_UNKNOWN = 'unknown';
exports.FSEVENT_TYPE_FILE = 'file';
exports.FSEVENT_TYPE_DIRECTORY = 'directory';
exports.FSEVENT_TYPE_SYMLINK = 'symlink';
@@ -40,6 +42,7 @@ exports.DOT_RE = /\..*\.(sw[px])$|~$|\.subl.*\.tmp/;
exports.REPLACER_RE = /^\.[/\\]/;
exports.SLASH = '/';
exports.SLASH_SLASH = '//';
exports.BRACE_START = '{';
exports.BANG = '!';
exports.ONE_DOT = '.';
@@ -58,3 +61,5 @@ exports.IDENTITY_FN = val => val;
exports.isWindows = platform === 'win32';
exports.isMacos = platform === 'darwin';
exports.isLinux = platform === 'linux';
exports.isIBMi = os.type() === 'OS400';

View File

@@ -37,6 +37,7 @@ const {
FSEVENT_MOVED,
// FSEVENT_CLONED,
FSEVENT_UNKNOWN,
FSEVENT_TYPE_FILE,
FSEVENT_TYPE_DIRECTORY,
FSEVENT_TYPE_SYMLINK,
@@ -47,13 +48,10 @@ const {
EMPTY_FN,
IDENTITY_FN
} = require('./constants');
const FS_MODE_READ = 'r';
const Depth = (value) => isNaN(value) ? {} : {depth: value};
const stat = promisify(fs.stat);
const open = promisify(fs.open);
const close = promisify(fs.close);
const lstat = promisify(fs.lstat);
const realpath = promisify(fs.realpath);
@@ -105,8 +103,9 @@ const createFSEventsInstance = (path, callback) => {
* @param {Function} rawEmitter - passes data to listeners of the 'raw' event
* @returns {Function} closer
*/
function setFSEventsListener(path, realPath, listener, rawEmitter, fsw) {
let watchPath = sysPath.extname(path) ? sysPath.dirname(path) : path;
function setFSEventsListener(path, realPath, listener, rawEmitter) {
let watchPath = sysPath.extname(realPath) ? sysPath.dirname(realPath) : realPath;
const parentPath = sysPath.dirname(watchPath);
let cont = FSEventsWatchers.get(watchPath);
@@ -148,7 +147,7 @@ function setFSEventsListener(path, realPath, listener, rawEmitter, fsw) {
listeners: new Set([filteredListener]),
rawEmitter,
watcher: createFSEventsInstance(watchPath, (fullPath, flags) => {
if (fsw.closed) return;
if (!cont.listeners.size) return;
const info = fsevents.getInfo(fullPath, flags);
cont.listeners.forEach(list => {
list(fullPath, flags, info);
@@ -202,6 +201,14 @@ const calcDepth = (path, root) => {
return i;
};
// returns boolean indicating whether the fsevents' event info has the same type
// as the one returned by fs.stat
const sameTypes = (info, stats) => (
info.type === FSEVENT_TYPE_DIRECTORY && stats.isDirectory() ||
info.type === FSEVENT_TYPE_SYMLINK && stats.isSymbolicLink() ||
info.type === FSEVENT_TYPE_FILE && stats.isFile()
)
/**
* @mixin
*/
@@ -232,13 +239,15 @@ addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
this.handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opts);
}
async checkFd(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
async checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts) {
try {
const fd = await open(path, FS_MODE_READ);
const stats = await stat(path)
if (this.fsw.closed) return;
await close(fd);
if (this.fsw.closed) return;
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
if (sameTypes(info, stats)) {
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
} else {
this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
}
} catch (error) {
if (error.code === 'EACCES') {
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
@@ -252,9 +261,10 @@ handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opt
if (this.fsw.closed || this.checkIgnored(path)) return;
if (event === EV_UNLINK) {
const isDirectory = info.type === FSEVENT_TYPE_DIRECTORY
// suppress unlink events on never before seen files
if (info.type === FSEVENT_TYPE_DIRECTORY || watchedDir.has(item)) {
this.fsw._remove(parent, item);
if (isDirectory || watchedDir.has(item)) {
this.fsw._remove(parent, item, isDirectory);
}
} else {
if (event === EV_ADD) {
@@ -290,8 +300,7 @@ handleEvent(event, path, fullPath, realPath, parent, watchedDir, item, info, opt
* @returns {Function} closer for the watcher instance
*/
_watchWithFsEvents(watchPath, realPath, transform, globFilter) {
if (this.fsw.closed) return;
if (this.fsw._isIgnored(watchPath)) return;
if (this.fsw.closed || this.fsw._isIgnored(watchPath)) return;
const opts = this.fsw.options;
const watchCallback = async (fullPath, flags, info) => {
if (this.fsw.closed) return;
@@ -319,13 +328,13 @@ _watchWithFsEvents(watchPath, realPath, transform, globFilter) {
} catch (error) {}
if (this.fsw.closed) return;
if (this.checkIgnored(path, stats)) return;
if (stats) {
if (sameTypes(info, stats)) {
this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
} else {
this.handleEvent(EV_UNLINK, path, fullPath, realPath, parent, watchedDir, item, info, opts);
}
} else {
this.checkFd(path, fullPath, realPath, parent, watchedDir, item, info, opts);
this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
}
} else {
switch (info.event) {
@@ -334,7 +343,7 @@ _watchWithFsEvents(watchPath, realPath, transform, globFilter) {
return this.addOrChange(path, fullPath, realPath, parent, watchedDir, item, info, opts);
case FSEVENT_DELETED:
case FSEVENT_MOVED:
return this.checkFd(path, fullPath, realPath, parent, watchedDir, item, info, opts);
return this.checkExists(path, fullPath, realPath, parent, watchedDir, item, info, opts);
}
}
};
@@ -343,8 +352,7 @@ _watchWithFsEvents(watchPath, realPath, transform, globFilter) {
watchPath,
realPath,
watchCallback,
this.fsw._emitRaw,
this.fsw
this.fsw._emitRaw
);
this.fsw._emitReady();

View File

@@ -6,6 +6,7 @@ const { promisify } = require('util');
const isBinaryPath = require('is-binary-path');
const {
isWindows,
isLinux,
EMPTY_FN,
EMPTY_STR,
KEY_LISTENERS,
@@ -356,8 +357,7 @@ _handleFile(file, stats, initialAdd) {
// if the file is already being watched, do nothing
if (parent.has(basename)) return;
// kick off the watcher
const closer = this._watchWithNodeFs(file, async (path, newStats) => {
const listener = async (path, newStats) => {
if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5)) return;
if (!newStats || newStats.mtimeMs === 0) {
try {
@@ -369,12 +369,18 @@ _handleFile(file, stats, initialAdd) {
if (!at || at <= mt || mt !== prevStats.mtimeMs) {
this.fsw._emit(EV_CHANGE, file, newStats);
}
prevStats = newStats;
if (isLinux && prevStats.ino !== newStats.ino) {
this.fsw._closeFile(path)
prevStats = newStats;
this.fsw._addPathCloser(path, this._watchWithNodeFs(file, listener));
} else {
prevStats = newStats;
}
} catch (error) {
// Fix issues where mtime is null but file is still present
this.fsw._remove(dirname, basename);
}
// add is about to be emitted if file not already tracked in parent
// add is about to be emitted if file not already tracked in parent
} else if (parent.has(basename)) {
// Check that change event was not fired because of changed only accessTime.
const at = newStats.atimeMs;
@@ -384,7 +390,9 @@ _handleFile(file, stats, initialAdd) {
}
prevStats = newStats;
}
});
}
// kick off the watcher
const closer = this._watchWithNodeFs(file, listener);
// emit an add event if we're supposed to
if (!(initialAdd && this.fsw.options.ignoreInitial) && this.fsw._isntIgnored(file)) {
@@ -413,7 +421,15 @@ async _handleSymlink(entry, directory, path, item) {
if (!this.fsw.options.followSymlinks) {
// watch symlink directly (don't follow) and detect changes
this.fsw._incrReadyCount();
const linkPath = await fsrealpath(path);
let linkPath;
try {
linkPath = await fsrealpath(path);
} catch (e) {
this.fsw._emitReady();
return true;
}
if (this.fsw.closed) return;
if (dir.has(item)) {
if (this.fsw._symlinkPaths.get(full) !== linkPath) {
@@ -595,13 +611,14 @@ async _addToNodeFs(path, initialAdd, priorWh, depth, target) {
const follow = this.fsw.options.followSymlinks && !path.includes(STAR) && !path.includes(BRACE_START);
let closer;
if (stats.isDirectory()) {
const absPath = sysPath.resolve(path);
const targetPath = follow ? await fsrealpath(path) : path;
if (this.fsw.closed) return;
closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
if (this.fsw.closed) return;
// preserve this symlink's target path
if (path !== targetPath && targetPath !== undefined) {
this.fsw._symlinkPaths.set(targetPath, true);
if (absPath !== targetPath && targetPath !== undefined) {
this.fsw._symlinkPaths.set(absPath, targetPath);
}
} else if (stats.isSymbolicLink()) {
const targetPath = follow ? await fsrealpath(path) : path;