Fix:Include Watcher as lib with no dependencies and fix tiny-readdir bug #610

This commit is contained in:
advplyr 2022-05-28 20:01:20 -05:00
parent 160dac109d
commit ec6e70725c
34 changed files with 2187 additions and 281 deletions

View file

@ -0,0 +1,19 @@
"use strict";
/* CONSTS */
Object.defineProperty(exports, "__esModule", { value: true });
exports.S_IFSOCK = exports.S_IFREG = exports.S_IFMT = exports.S_IFLNK = exports.S_IFIFO = exports.S_IFDIR = exports.S_IFCHR = exports.S_IFBLK = exports.RETRY_TIMEOUT = exports.MAX_SAFE_INTEGER = exports.IS_WINDOWS = void 0;
const IS_WINDOWS = (process.platform === 'win32');
exports.IS_WINDOWS = IS_WINDOWS;
const { MAX_SAFE_INTEGER } = Number;
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
const RETRY_TIMEOUT = 5000;
exports.RETRY_TIMEOUT = RETRY_TIMEOUT;
const { S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFMT, S_IFREG, S_IFSOCK } = process['binding']('constants').fs;
exports.S_IFBLK = S_IFBLK;
exports.S_IFCHR = S_IFCHR;
exports.S_IFDIR = S_IFDIR;
exports.S_IFIFO = S_IFIFO;
exports.S_IFLNK = S_IFLNK;
exports.S_IFMT = S_IFMT;
exports.S_IFREG = S_IFREG;
exports.S_IFSOCK = S_IFSOCK;

View file

@ -0,0 +1,39 @@
"use strict";
/* IMPORT */
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stats = void 0;
const fs_1 = require("../atomically/utils/fs");
const path_1 = require("path");
const consts_1 = require("./consts");
const stats_1 = require("./stats");
exports.Stats = stats_1.default;
/* HELPERS */
const { stat, FSReqCallback } = process['binding']('fs');
/* RIPSTAT */
const ripstat = (filePath, timeout) => {
return new Promise((resolve, reject) => {
const req = new FSReqCallback(true);
req.oncomplete = (error, statsdata) => {
if (error) {
const { code } = error;
if (code === 'EMFILE' || code === 'ENFILE' || code === 'EAGAIN' || code === 'EBUSY' || code === 'EACCESS' || code === 'EACCS' || code === 'EPERM') { // Retriable error
fs_1.default.statRetry(timeout || consts_1.RETRY_TIMEOUT)(filePath, { bigint: true }).then(nstats => {
const statsdata = [nstats.dev, nstats.mode, nstats.nlink, nstats.uid, nstats.gid, nstats.rdev, nstats.blksize, nstats.ino, nstats.size, nstats.blocks, 0n, nstats.atimeNs, 0n, nstats.mtimeNs, 0n, nstats.ctimeNs, 0n, nstats.birthtimeNs];
const stats = new stats_1.default(statsdata);
resolve(stats);
}, reject);
}
else {
reject(error);
}
}
else {
const stats = new stats_1.default(statsdata);
resolve(stats);
}
};
stat(path_1.toNamespacedPath(filePath), true, req);
});
};
/* EXPORT */
exports.default = ripstat;

View file

@ -0,0 +1,55 @@
"use strict";
/* IMPORT */
Object.defineProperty(exports, "__esModule", { value: true });
const consts_1 = require("./consts");
/* HELPERS */
const { floor } = Math;
const toNumber = Number;
/* STATS */
class Stats {
/* CONSTRUCTOR */
constructor(stats) {
this.dev = toNumber(stats[0]);
this.mode = toNumber(stats[1]);
this.nlink = toNumber(stats[2]);
this.uid = toNumber(stats[3]);
this.gid = toNumber(stats[4]);
this.rdev = toNumber(stats[5]);
this.blksize = toNumber(stats[6]);
this.ino = (stats[7] <= consts_1.MAX_SAFE_INTEGER) ? toNumber(stats[7]) : stats[7];
this.size = toNumber(stats[8]);
this.blocks = toNumber(stats[9]);
this.atimeMs = (toNumber(stats[10]) * 1000) + floor(toNumber(stats[11]) / 1000000);
this.mtimeMs = (toNumber(stats[12]) * 1000) + floor(toNumber(stats[13]) / 1000000);
this.ctimeMs = (toNumber(stats[14]) * 1000) + floor(toNumber(stats[15]) / 1000000);
this.birthtimeMs = (toNumber(stats[16]) * 1000) + floor(toNumber(stats[17]) / 1000000);
}
/* HELPERS */
_isMode(mode) {
return (this.mode & consts_1.S_IFMT) === mode;
}
/* API */
isDirectory() {
return this._isMode(consts_1.S_IFDIR);
}
isFile() {
return this._isMode(consts_1.S_IFREG);
}
isBlockDevice() {
return !consts_1.IS_WINDOWS && this._isMode(consts_1.S_IFBLK);
}
isCharacterDevice() {
return this._isMode(consts_1.S_IFCHR);
}
isSymbolicLink() {
return this._isMode(consts_1.S_IFLNK);
}
isFIFO() {
return !consts_1.IS_WINDOWS && this._isMode(consts_1.S_IFIFO);
}
isSocket() {
return !consts_1.IS_WINDOWS && this._isMode(consts_1.S_IFSOCK);
}
}
/* EXPORT */
exports.default = Stats;