mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 23:20:05 +02:00
Fix:Include Watcher as lib with no dependencies and fix tiny-readdir bug #610
This commit is contained in:
parent
160dac109d
commit
ec6e70725c
34 changed files with 2187 additions and 281 deletions
39
server/libs/watcher/ripstat/index.js
Normal file
39
server/libs/watcher/ripstat/index.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue