Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@renarsvilnis/dir-compare

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@renarsvilnis/dir-compare - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

src/index.ts

496

lib/compareAsync.js
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __spreadArrays = (this && this.__spreadArrays) || function () {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -49,187 +6,158 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var path_1 = __importDefault(require("path"));
var util_1 = require("util");
var createDifference_1 = require("./utils/createDifference");
var utils_1 = require("./utils");
var statAsync = util_1.promisify(fs_1.default.stat);
var readdirAsync = util_1.promisify(fs_1.default.readdir);
var lstatAsync = util_1.promisify(fs_1.default.lstat);
function compareAsyncInternal(_a) {
var rootEntry1 = _a.rootEntry1, rootEntry2 = _a.rootEntry2, level = _a.level, relativePath = _a.relativePath, searchOptions = _a.searchOptions, symlinkCache = _a.symlinkCache, onDifference = _a.onDifference;
return __awaiter(this, void 0, void 0, function () {
var loopDetected1, symlinkCachePath1, loopDetected2, symlinkCachePath2, absolutePath1, absolutePath2, path1, path2, _b, entries1, entries2, comparePromises, compareFilePromises, i1, i2, entries1LengthCached, entries2LengthCached, _loop_1;
var _this = this;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
loopDetected1 = utils_1.detectLoop(rootEntry1, symlinkCache.dir1);
if (rootEntry1 && !loopDetected1) {
symlinkCachePath1 = rootEntry1.isSymlink ? fs_1.default.realpathSync(rootEntry1.absolutePath) : rootEntry1.absolutePath;
symlinkCache.dir1[symlinkCachePath1] = true;
}
loopDetected2 = utils_1.detectLoop(rootEntry2, symlinkCache.dir2);
if (rootEntry2 && !loopDetected2) {
symlinkCachePath2 = rootEntry2.isSymlink ? fs_1.default.realpathSync(rootEntry2.absolutePath) : rootEntry2.absolutePath;
symlinkCache.dir2[symlinkCachePath2] = true;
}
absolutePath1 = rootEntry1 ? rootEntry1.absolutePath : undefined;
absolutePath2 = rootEntry2 ? rootEntry2.absolutePath : undefined;
path1 = rootEntry1 ? rootEntry1.path : undefined;
path2 = rootEntry2 ? rootEntry2.path : undefined;
return [4 /*yield*/, Promise.all([
getEntries(absolutePath1, path1, searchOptions, loopDetected1),
getEntries(absolutePath2, path2, searchOptions, loopDetected2)
])];
case 1:
_b = _c.sent(), entries1 = _b[0], entries2 = _b[1];
comparePromises = [];
compareFilePromises = [];
i1 = 0;
i2 = 0;
entries1LengthCached = entries1.length;
entries2LengthCached = entries2.length;
_loop_1 = function () {
var entry1, entry2, fileStat1, fileStat2, type1, type2, cmp, onSame, same, compareFile;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
entry1 = entries1[i1];
entry2 = entries2[i2];
fileStat1 = entry1 ? entry1.stat : undefined;
fileStat2 = entry2 ? entry2.stat : undefined;
type1 = void 0;
type2 = void 0;
cmp = void 0;
if (i1 < entries1LengthCached && i2 < entries2LengthCached) {
type1 = utils_1.getTypeLoose(fileStat1);
type2 = utils_1.getTypeLoose(fileStat2);
cmp = searchOptions.ignoreCase
? utils_1.compareEntryIgnoreCase(entry1, entry2)
: utils_1.compareEntryCaseSensitive(entry1, entry2);
}
else if (i1 < entries1LengthCached) {
type1 = utils_1.getTypeLoose(fileStat1);
type2 = "missing";
cmp = -1;
}
else {
type1 = "missing";
type2 = utils_1.getTypeLoose(fileStat2);
cmp = 1;
}
onSame = function (isSame) {
return onDifference(isSame
? createDifference_1.createEqualDifference(entry1, entry2, level, relativePath)
: createDifference_1.createDistinctDifference(entry1, entry2, level, relativePath));
};
// process entry
if (cmp === 0) {
same = undefined;
if (type1 === "file") {
// TODO: maybe convert so that multiple compare "filters" can be applied,
// as now you need to choose compareSize or compareDate or
// compareContent, maybe user wants to compare everything
// TODO: fix type enforce
if (searchOptions.compareSize && fileStat1.size !== fileStat2.size) {
same = false;
}
else if (searchOptions.compareDate &&
// TODO: fix type enforce
!utils_1.sameDate(fileStat1.mtime, fileStat2.mtime, searchOptions.dateTolerance)) {
same = false;
}
else if (searchOptions.compareContent) {
compareFile = function () { return __awaiter(_this, void 0, void 0, function () {
var isSame;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, searchOptions.compareFile(entry1.absolutePath, entry1.stat, entry2.absolutePath, entry2.stat, searchOptions)];
case 1:
isSame = _a.sent();
onSame(isSame);
return [2 /*return*/];
}
});
}); };
compareFilePromises.push(compareFile());
}
else {
same = true;
}
// Folder
}
else {
same = true;
}
if (same !== undefined) {
onSame(same);
}
i1++;
i2++;
if (!searchOptions.skipSubdirectories && type1 === "directory") {
comparePromises.push(compareAsyncInternal({
rootEntry1: entry1,
rootEntry2: entry2,
level: level + 1,
relativePath: utils_1.fastPathJoin(relativePath, entry1.name),
searchOptions: searchOptions,
onDifference: onDifference,
// TODO: why do i need clone it, maybe DeepReadonly<>?
symlinkCache: utils_1.cloneSymlinkCache(symlinkCache)
}));
}
}
else if (cmp < 0) {
// Right missing
onDifference(createDifference_1.createLeftOnlyDifference(entry1, level, relativePath));
i1++;
if (!searchOptions.skipSubdirectories && type1 === "directory") {
comparePromises.push(compareAsyncInternal({
rootEntry1: entry1,
rootEntry2: undefined,
level: level + 1,
relativePath: utils_1.fastPathJoin(relativePath, entry1.name),
searchOptions: searchOptions,
onDifference: onDifference,
// TODO: same issue as above
symlinkCache: utils_1.cloneSymlinkCache(symlinkCache)
}));
}
}
else {
// Left missing
onDifference(createDifference_1.createRightOnlyDifference(entry2, level, relativePath));
i2++;
if (!searchOptions.skipSubdirectories && type2 === "directory") {
comparePromises.push(compareAsyncInternal({
rootEntry1: undefined,
rootEntry2: entry2,
level: level + 1,
relativePath: utils_1.fastPathJoin(relativePath, entry2.name),
searchOptions: searchOptions,
onDifference: onDifference,
// TODO: same symlink issue as before
symlinkCache: utils_1.cloneSymlinkCache(symlinkCache)
}));
}
}
return [4 /*yield*/, Promise.all(__spreadArrays(comparePromises, compareFilePromises))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const util_1 = require("util");
const createDifference_1 = require("./utils/createDifference");
const utils_1 = require("./utils");
const statAsync = util_1.promisify(fs_1.default.stat);
const readdirAsync = util_1.promisify(fs_1.default.readdir);
const lstatAsync = util_1.promisify(fs_1.default.lstat);
async function compareAsyncInternal({ rootEntry1, rootEntry2, level, relativePath, searchOptions, symlinkCache, onDifference }) {
const loopDetected1 = utils_1.detectLoop(rootEntry1, symlinkCache.dir1);
if (rootEntry1 && !loopDetected1) {
const symlinkCachePath1 = rootEntry1.isSymlink ? fs_1.default.realpathSync(rootEntry1.absolutePath) : rootEntry1.absolutePath;
symlinkCache.dir1[symlinkCachePath1] = true;
}
const loopDetected2 = utils_1.detectLoop(rootEntry2, symlinkCache.dir2);
if (rootEntry2 && !loopDetected2) {
const symlinkCachePath2 = rootEntry2.isSymlink ? fs_1.default.realpathSync(rootEntry2.absolutePath) : rootEntry2.absolutePath;
symlinkCache.dir2[symlinkCachePath2] = true;
}
const absolutePath1 = rootEntry1 ? rootEntry1.absolutePath : undefined;
const absolutePath2 = rootEntry2 ? rootEntry2.absolutePath : undefined;
const path1 = rootEntry1 ? rootEntry1.path : undefined;
const path2 = rootEntry2 ? rootEntry2.path : undefined;
const [entries1, entries2] = await Promise.all([
getEntries(absolutePath1, path1, searchOptions, loopDetected1),
getEntries(absolutePath2, path2, searchOptions, loopDetected2)
]);
const comparePromises = [];
const compareFilePromises = [];
/**
* Index of which entry from each group to process, once an entry from a group
* is processed the groups index variable gets incremented
*/
let i1 = 0;
let i2 = 0;
// Cache entries length property as their length is static
const entries1LengthCached = entries1.length;
const entries2LengthCached = entries2.length;
// Loop while both entries are processed
while (i1 < entries1LengthCached || i2 < entries2LengthCached) {
const entry1 = entries1[i1];
const entry2 = entries2[i2];
const fileStat1 = entry1 ? entry1.stat : undefined;
const fileStat2 = entry2 ? entry2.stat : undefined;
let type1;
let type2;
let cmp;
if (i1 < entries1LengthCached && i2 < entries2LengthCached) {
type1 = utils_1.getTypeLoose(fileStat1);
type2 = utils_1.getTypeLoose(fileStat2);
cmp = searchOptions.ignoreCase
? utils_1.compareEntryIgnoreCase(entry1, entry2)
: utils_1.compareEntryCaseSensitive(entry1, entry2);
}
else if (i1 < entries1LengthCached) {
type1 = utils_1.getTypeLoose(fileStat1);
type2 = "missing";
cmp = -1;
}
else {
type1 = "missing";
type2 = utils_1.getTypeLoose(fileStat2);
cmp = 1;
}
// "dry method" because used in two spaces
const onSame = (isSame) => onDifference(isSame
? createDifference_1.createEqualDifference(entry1, entry2, level, relativePath)
: createDifference_1.createDistinctDifference(entry1, entry2, level, relativePath));
// process entry
if (cmp === 0) {
// Both left/right exist and have the same name and type
let same = undefined;
if (type1 === "file") {
// TODO: maybe convert so that multiple compare "filters" can be applied,
// as now you need to choose compareSize or compareDate or
// compareContent, maybe user wants to compare everything
// TODO: fix type enforce
if (searchOptions.compareSize && fileStat1.size !== fileStat2.size) {
same = false;
}
else if (searchOptions.compareDate &&
// TODO: fix type enforce
!utils_1.sameDate(fileStat1.mtime, fileStat2.mtime, searchOptions.dateTolerance)) {
same = false;
}
else if (searchOptions.compareContent) {
const compareFile = async () => {
// TODO: improve code so that no need to force type entry1.stat! and
// entry2.stat!
const isSame = await searchOptions.compareFile(entry1.absolutePath, entry1.stat, entry2.absolutePath, entry2.stat, searchOptions);
onSame(isSame);
};
_c.label = 2;
case 2:
if (!(i1 < entries1LengthCached || i2 < entries2LengthCached)) return [3 /*break*/, 4];
return [5 /*yield**/, _loop_1()];
case 3:
_c.sent();
return [3 /*break*/, 2];
case 4: return [2 /*return*/];
compareFilePromises.push(compareFile());
}
else {
same = true;
}
// Folder
}
});
});
else {
same = true;
}
if (same !== undefined) {
onSame(same);
}
i1++;
i2++;
if (!searchOptions.skipSubdirectories && type1 === "directory") {
comparePromises.push(compareAsyncInternal({
rootEntry1: entry1,
rootEntry2: entry2,
level: level + 1,
relativePath: utils_1.fastPathJoin(relativePath, entry1.name),
searchOptions,
onDifference,
// TODO: why do i need clone it, maybe DeepReadonly<>?
symlinkCache: utils_1.cloneSymlinkCache(symlinkCache)
}));
}
}
else if (cmp < 0) {
// Right missing
onDifference(createDifference_1.createLeftOnlyDifference(entry1, level, relativePath));
i1++;
if (!searchOptions.skipSubdirectories && type1 === "directory") {
comparePromises.push(compareAsyncInternal({
rootEntry1: entry1,
rootEntry2: undefined,
level: level + 1,
relativePath: utils_1.fastPathJoin(relativePath, entry1.name),
searchOptions,
onDifference,
// TODO: same issue as above
symlinkCache: utils_1.cloneSymlinkCache(symlinkCache)
}));
}
}
else {
// Left missing
onDifference(createDifference_1.createRightOnlyDifference(entry2, level, relativePath));
i2++;
if (!searchOptions.skipSubdirectories && type2 === "directory") {
comparePromises.push(compareAsyncInternal({
rootEntry1: undefined,
rootEntry2: entry2,
level: level + 1,
relativePath: utils_1.fastPathJoin(relativePath, entry2.name),
searchOptions,
onDifference,
// TODO: same symlink issue as before
symlinkCache: utils_1.cloneSymlinkCache(symlinkCache)
}));
}
}
await Promise.all([...comparePromises, ...compareFilePromises]);
}
}

@@ -240,82 +168,44 @@ exports.default = compareAsyncInternal;

*/
function getEntries(absolutePath, path, searchOptions, loopDetected) {
return __awaiter(this, void 0, void 0, function () {
var stat, rawEntries, name, lstat, isSymlink;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!absolutePath || !path || loopDetected) {
return [2 /*return*/, []];
}
return [4 /*yield*/, statAsync(absolutePath)];
case 1:
stat = _a.sent();
if (!stat.isDirectory()) return [3 /*break*/, 3];
return [4 /*yield*/, readdirAsync(absolutePath)];
case 2:
rawEntries = _a.sent();
return [2 /*return*/, buildEntries(absolutePath, path, rawEntries, searchOptions)];
case 3:
name = path_1.default.basename(absolutePath);
return [4 /*yield*/, lstatAsync(absolutePath)];
case 4:
lstat = _a.sent();
isSymlink = lstat.isSymbolicLink();
return [2 /*return*/, [{ name: name, absolutePath: absolutePath, path: path, stat: stat, lstat: lstat, isSymlink: isSymlink }]];
}
});
});
async function getEntries(absolutePath, path, searchOptions, loopDetected) {
if (!absolutePath || !path || loopDetected) {
return [];
}
const stat = await statAsync(absolutePath);
if (stat.isDirectory()) {
const rawEntries = await readdirAsync(absolutePath);
return buildEntries(absolutePath, path, rawEntries, searchOptions);
}
else {
const name = path_1.default.basename(absolutePath);
const lstat = await lstatAsync(absolutePath);
const isSymlink = lstat.isSymbolicLink();
return [{ name, absolutePath, path, stat, lstat, isSymlink }];
}
}
function buildEntries(absolutePath, path, rawEntries, searchOptions) {
return __awaiter(this, void 0, void 0, function () {
var entries, filteredEntries;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Promise.all(rawEntries.map(function (entryName) { return buildEntry(absolutePath, path, entryName, searchOptions); }))];
case 1:
entries = _a.sent();
filteredEntries = entries.filter(function (entry) { return utils_1.filterEntry(entry, searchOptions); });
return [2 /*return*/, searchOptions.ignoreCase
? filteredEntries.sort(utils_1.compareEntryIgnoreCase)
: filteredEntries.sort(utils_1.compareEntryCaseSensitive)];
}
});
});
async function buildEntries(absolutePath, path, rawEntries, searchOptions) {
const entries = await Promise.all(rawEntries.map(entryName => buildEntry(absolutePath, path, entryName, searchOptions)));
const filteredEntries = entries.filter(entry => utils_1.filterEntry(entry, searchOptions));
return searchOptions.ignoreCase
? filteredEntries.sort(utils_1.compareEntryIgnoreCase)
: filteredEntries.sort(utils_1.compareEntryCaseSensitive);
}
function buildEntry(absolutePath, path, entryName, searchOptions) {
return __awaiter(this, void 0, void 0, function () {
var entryAbsolutePath, entryPath, lstat, isSymlink, stat, _a;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
entryAbsolutePath = utils_1.fastPathJoin(absolutePath, entryName);
entryPath = utils_1.fastPathJoin(path, entryName);
return [4 /*yield*/, lstatAsync(entryAbsolutePath)];
case 1:
lstat = _b.sent();
isSymlink = lstat.isSymbolicLink();
if (!(searchOptions.skipSymlinks && isSymlink)) return [3 /*break*/, 2];
_a = undefined;
return [3 /*break*/, 4];
case 2: return [4 /*yield*/, statAsync(entryAbsolutePath)];
case 3:
_a = _b.sent();
_b.label = 4;
case 4:
stat = _a;
// TODO: for now disable the optimization to make types easier
// const [lstat, stat] = await Promise.all([lstatAsync(entryAbsolutePath), statAsync(entryAbsolutePath)]);
// const isSymlink = lstat.isSymbolicLink();
return [2 /*return*/, {
name: entryName,
absolutePath: entryAbsolutePath,
path: entryPath,
stat: stat,
lstat: lstat,
isSymlink: isSymlink
}];
}
});
});
async function buildEntry(absolutePath, path, entryName, searchOptions) {
const entryAbsolutePath = utils_1.fastPathJoin(absolutePath, entryName);
const entryPath = utils_1.fastPathJoin(path, entryName);
const lstat = await lstatAsync(entryAbsolutePath);
const isSymlink = lstat.isSymbolicLink();
// Memory usage optimization if user doesn't want to follow symlinks
const stat = searchOptions.skipSymlinks && isSymlink ? undefined : await statAsync(entryAbsolutePath);
// TODO: for now disable the optimization to make types easier
// const [lstat, stat] = await Promise.all([lstatAsync(entryAbsolutePath), statAsync(entryAbsolutePath)]);
// const isSymlink = lstat.isSymbolicLink();
return {
name: entryName,
absolutePath: entryAbsolutePath,
path: entryPath,
stat,
lstat,
isSymlink
};
}
//# sourceMappingURL=compareAsync.js.map
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -49,61 +13,50 @@ if (mod && mod.__esModule) return mod;

Object.defineProperty(exports, "__esModule", { value: true });
var pathUtils = __importStar(require("path"));
var fs = __importStar(require("fs"));
var util_1 = require("util");
var compareAsync_1 = __importDefault(require("./compareAsync"));
const pathUtils = __importStar(require("path"));
const fs = __importStar(require("fs"));
const util_1 = require("util");
const compareAsync_1 = __importDefault(require("./compareAsync"));
// import defaultFileCompare from "./fileCompareHandlers/defaultFileCompare";
var utils_1 = require("./utils");
var Statistics_1 = __importDefault(require("./utils/Statistics"));
var realpathAsync = util_1.promisify(fs.realpath);
function dirCompare(path1, path2, options) {
return __awaiter(this, void 0, void 0, function () {
var _a, realPath1, realPath2, absolutePath1, absolutePath2, statistics, differences, symlinkCache, onDifference, _b, rootEntry1, rootEntry2;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
if (!pathUtils.isAbsolute(path1)) {
throw new Error("path1 must be an absolute path");
}
if (!pathUtils.isAbsolute(path2)) {
throw new Error("path2 must be an absolute path");
}
return [4 /*yield*/, Promise.all([realpathAsync(path1), realpathAsync(path2)])];
case 1:
_a = _c.sent(), realPath1 = _a[0], realPath2 = _a[1];
absolutePath1 = pathUtils.normalize(pathUtils.resolve(realPath1));
absolutePath2 = pathUtils.normalize(pathUtils.resolve(realPath2));
statistics = new Statistics_1.default();
differences = [];
symlinkCache = utils_1.symlinkCacheFactory();
onDifference = function (difference) {
statistics.addDifference(difference);
differences.push(difference);
};
return [4 /*yield*/, Promise.all([
utils_1.entryRootFactory(absolutePath1, path1, pathUtils.basename(path1)),
utils_1.entryRootFactory(absolutePath2, path2, pathUtils.basename(path2))
])];
case 2:
_b = _c.sent(), rootEntry1 = _b[0], rootEntry2 = _b[1];
// TODO: implement progress, need to figure out how to get totalCount before
// and also take care of options
return [4 /*yield*/, compareAsync_1.default({
// rootEntry1: entryRootFactory(absolutePath1, path1, pathUtils.basename(path1)),
// rootEntry2: entryRootFactory(absolutePath2, path2, pathUtils.basename(path2)),
rootEntry1: rootEntry1,
rootEntry2: rootEntry2,
level: 0,
relativePath: "",
searchOptions: options,
symlinkCache: symlinkCache,
onDifference: onDifference
})];
case 3:
// TODO: implement progress, need to figure out how to get totalCount before
// and also take care of options
_c.sent();
return [2 /*return*/, { statistics: statistics.toObject(), differences: differences }];
}
});
const utils_1 = require("./utils");
const Statistics_1 = __importDefault(require("./utils/Statistics"));
const realpathAsync = util_1.promisify(fs.realpath);
async function dirCompare(path1, path2, options) {
if (!pathUtils.isAbsolute(path1)) {
throw new Error("path1 must be an absolute path");
}
if (!pathUtils.isAbsolute(path2)) {
throw new Error("path2 must be an absolute path");
}
const [realPath1, realPath2] = await Promise.all([realpathAsync(path1), realpathAsync(path2)]);
// realpath() is necessary for loop detection to work properly
const absolutePath1 = pathUtils.normalize(pathUtils.resolve(realPath1));
const absolutePath2 = pathUtils.normalize(pathUtils.resolve(realPath2));
// TODO: make optional?
const statistics = new Statistics_1.default();
// // TODO: improve prepareOptions
// options = prepareOptions(options);
const differences = [];
const symlinkCache = utils_1.symlinkCacheFactory();
const onDifference = (difference) => {
statistics.addDifference(difference);
differences.push(difference);
};
// TODO: verify if the async entryRootFactory method works as expected after tests
const [rootEntry1, rootEntry2] = await Promise.all([
utils_1.entryRootFactory(absolutePath1, path1, pathUtils.basename(path1)),
utils_1.entryRootFactory(absolutePath2, path2, pathUtils.basename(path2))
]);
// TODO: implement progress, need to figure out how to get totalCount before
// and also take care of options
await compareAsync_1.default({
// rootEntry1: entryRootFactory(absolutePath1, path1, pathUtils.basename(path1)),
// rootEntry2: entryRootFactory(absolutePath2, path2, pathUtils.basename(path2)),
rootEntry1,
rootEntry2,
level: 0,
relativePath: "",
searchOptions: options,
symlinkCache,
onDifference
});
return { statistics: statistics.toObject(), differences };
}

@@ -110,0 +63,0 @@ exports.default = dirCompare;

@@ -6,12 +6,12 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var buffer_equal_1 = __importDefault(require("buffer-equal"));
var fs_1 = __importDefault(require("fs"));
var util_1 = require("util");
var FileDescriptorQueue_1 = __importDefault(require("../utils/FileDescriptorQueue"));
var BufferPool_1 = __importDefault(require("../utils/BufferPool"));
var MAX_CONCURRENT_FILE_COMPARE = 8;
var BUF_SIZE = 100000;
var fdQueue = new FileDescriptorQueue_1.default(MAX_CONCURRENT_FILE_COMPARE * 2);
var readAsync = util_1.promisify(fs_1.default.read);
var bufferPool = new BufferPool_1.default(BUF_SIZE, MAX_CONCURRENT_FILE_COMPARE); // fdQueue guarantees there will be no more than MAX_CONCURRENT_FILE_COMPARE async processes accessing the buffers concurrently
const buffer_equal_1 = __importDefault(require("buffer-equal"));
const fs_1 = __importDefault(require("fs"));
const util_1 = require("util");
const FileDescriptorQueue_1 = __importDefault(require("../utils/FileDescriptorQueue"));
const BufferPool_1 = __importDefault(require("../utils/BufferPool"));
const MAX_CONCURRENT_FILE_COMPARE = 8;
const BUF_SIZE = 100000;
const fdQueue = new FileDescriptorQueue_1.default(MAX_CONCURRENT_FILE_COMPARE * 2);
const readAsync = util_1.promisify(fs_1.default.read);
const bufferPool = new BufferPool_1.default(BUF_SIZE, MAX_CONCURRENT_FILE_COMPARE); // fdQueue guarantees there will be no more than MAX_CONCURRENT_FILE_COMPARE async processes accessing the buffers concurrently
/**

@@ -24,17 +24,15 @@ * Compares two files by content

options) {
var fd1;
var fd2;
var bufferPair;
let fd1;
let fd2;
let bufferPair;
return Promise.all([fdQueue.open(path1, "r"), fdQueue.open(path2, "r")])
.then(function (_a) {
var fd1 = _a[0], fd2 = _a[1];
.then(([fd1, fd2]) => {
bufferPair = bufferPool.allocateBuffers();
var buf1 = bufferPair.buf1;
var buf2 = bufferPair.buf2;
const buf1 = bufferPair.buf1;
const buf2 = bufferPair.buf2;
// let progress = 0;
var compareAsyncInternal = function () {
return Promise.all([readAsync(fd1, buf1, 0, BUF_SIZE, null), readAsync(fd2, buf2, 0, BUF_SIZE, null)]).then(function (_a) {
var readResult1 = _a[0], readResult2 = _a[1];
var size1 = readResult1.bytesRead;
var size2 = readResult2.bytesRead;
const compareAsyncInternal = () => {
return Promise.all([readAsync(fd1, buf1, 0, BUF_SIZE, null), readAsync(fd2, buf2, 0, BUF_SIZE, null)]).then(([readResult1, readResult2]) => {
const size1 = readResult1.bytesRead;
const size2 = readResult2.bytesRead;
if (size1 !== size2) {

@@ -57,3 +55,3 @@ return false;

})
.finally(function () {
.finally(() => {
// NOTE: don't wait .close() to resolve for results

@@ -60,0 +58,0 @@ fd1 && fdQueue.close(fd1);

@@ -6,11 +6,11 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var util_1 = require("util");
var FileDescriptorQueue_1 = __importDefault(require("../utils/FileDescriptorQueue"));
var BufferPool_1 = __importDefault(require("../utils/BufferPool"));
var readAsync = util_1.promisify(fs_1.default.read);
var MAX_CONCURRENT_FILE_COMPARE = 8;
var BUF_SIZE = 100000;
var fdQueue = new FileDescriptorQueue_1.default(MAX_CONCURRENT_FILE_COMPARE * 2);
var bufferPool = new BufferPool_1.default(BUF_SIZE, MAX_CONCURRENT_FILE_COMPARE); // fdQueue guarantees there will be no more than MAX_CONCURRENT_FILE_COMPARE async processes accessing the buffers concurrently
const fs_1 = __importDefault(require("fs"));
const util_1 = require("util");
const FileDescriptorQueue_1 = __importDefault(require("../utils/FileDescriptorQueue"));
const BufferPool_1 = __importDefault(require("../utils/BufferPool"));
const readAsync = util_1.promisify(fs_1.default.read);
const MAX_CONCURRENT_FILE_COMPARE = 8;
const BUF_SIZE = 100000;
const fdQueue = new FileDescriptorQueue_1.default(MAX_CONCURRENT_FILE_COMPARE * 2);
const bufferPool = new BufferPool_1.default(BUF_SIZE, MAX_CONCURRENT_FILE_COMPARE); // fdQueue guarantees there will be no more than MAX_CONCURRENT_FILE_COMPARE async processes accessing the buffers concurrently
function lineBasedFileCompare(path1, stat1, path2, stat2,

@@ -20,23 +20,21 @@ // TODO: add only needed options

options) {
var fd1;
var fd2;
var bufferPair;
let fd1;
let fd2;
let bufferPair;
return Promise.all([fdQueue.open(path1, "r"), fdQueue.open(path2, "r")])
.then(function (_a) {
var fd1 = _a[0], fd2 = _a[1];
.then(([fd1, fd2]) => {
bufferPair = bufferPool.allocateBuffers();
var buf1 = bufferPair.buf1;
var buf2 = bufferPair.buf2;
const buf1 = bufferPair.buf1;
const buf2 = bufferPair.buf2;
// let progress = 0;
var last1 = "";
var last2 = "";
var compareAsyncInternal = function () {
return Promise.all([readAsync(fd1, buf1, 0, BUF_SIZE, null), readAsync(fd2, buf2, 0, BUF_SIZE, null)]).then(function (_a) {
var readResult1 = _a[0], readResult2 = _a[1];
var size1 = readResult1.bytesRead;
var size2 = readResult2.bytesRead;
var chunk1 = buf1.toString("utf8", 0, size1);
var chunk2 = buf2.toString("utf8", 0, size2);
var lines1 = (last1 + chunk1).split(/\n/);
var lines2 = (last2 + chunk2).split(/\n/);
let last1 = "";
let last2 = "";
const compareAsyncInternal = () => {
return Promise.all([readAsync(fd1, buf1, 0, BUF_SIZE, null), readAsync(fd2, buf2, 0, BUF_SIZE, null)]).then(([readResult1, readResult2]) => {
const size1 = readResult1.bytesRead;
const size2 = readResult2.bytesRead;
const chunk1 = buf1.toString("utf8", 0, size1);
const chunk2 = buf2.toString("utf8", 0, size2);
const lines1 = (last1 + chunk1).split(/\n/);
const lines2 = (last2 + chunk2).split(/\n/);
if (size1 === 0 && size2 === 0) {

@@ -61,3 +59,3 @@ // End of file reached

})
.finally(function () {
.finally(() => {
// NOTE: don't wait .close() to resolve for results

@@ -80,5 +78,5 @@ fd1 && fdQueue.close(fd1);

function compareLines(lines1, lines2, options) {
for (var i = 0; i < lines1.length - 1; i++) {
var line1 = lines1[i];
var line2 = lines2[i];
for (let i = 0; i < lines1.length - 1; i++) {
let line1 = lines1[i];
let line2 = lines2[i];
if (options.ignoreLineEnding) {

@@ -85,0 +83,0 @@ line1 = removeLineEnding(line1);

@@ -9,5 +9,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var dirCompare_1 = __importDefault(require("./dirCompare"));
var defaultFileCompare_1 = __importDefault(require("./fileCompareHandlers/defaultFileCompare"));
var lineBasedFileCompare_1 = __importDefault(require("./fileCompareHandlers/lineBasedFileCompare"));
const dirCompare_1 = __importDefault(require("./dirCompare"));
const defaultFileCompare_1 = __importDefault(require("./fileCompareHandlers/defaultFileCompare"));
const lineBasedFileCompare_1 = __importDefault(require("./fileCompareHandlers/lineBasedFileCompare"));
__export(require("./types"));

@@ -14,0 +14,0 @@ exports.default = dirCompare_1.default;

"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importStar = (this && this.__importStar) || function (mod) {

@@ -60,8 +13,8 @@ if (mod && mod.__esModule) return mod;

Object.defineProperty(exports, "__esModule", { value: true });
var fs = __importStar(require("fs"));
var minimatch_1 = __importDefault(require("minimatch"));
var path_1 = __importDefault(require("path"));
var util_1 = require("util");
var statAsync = util_1.promisify(fs.stat);
var lstatAsync = util_1.promisify(fs.lstat);
const fs = __importStar(require("fs"));
const minimatch_1 = __importDefault(require("minimatch"));
const path_1 = __importDefault(require("path"));
const util_1 = require("util");
const statAsync = util_1.promisify(fs.stat);
const lstatAsync = util_1.promisify(fs.lstat);
// Instead of shallow copy

@@ -82,3 +35,3 @@ // https://stackoverflow.com/a/10916838/1378261

// TODO: why is it sync, maybe make it async after implementing tests
var realPath = fs.realpathSync(entry.absolutePath);
const realPath = fs.realpathSync(entry.absolutePath);
if (symlinkCacheGroup[realPath]) {

@@ -93,4 +46,4 @@ return true;

return {
dir1: __assign({}, symlinkCache.dir1),
dir2: __assign({}, symlinkCache.dir2)
dir1: { ...symlinkCache.dir1 },
dir2: { ...symlinkCache.dir2 }
};

@@ -119,21 +72,15 @@ }

// }
function entryRootFactory(absolutePath, path, name) {
return __awaiter(this, void 0, void 0, function () {
var _a, statEntry, lstatEntry;
return __generator(this, function (_b) {
switch (_b.label) {
case 0: return [4 /*yield*/, Promise.all([statAsync(absolutePath), lstatAsync(absolutePath)])];
case 1:
_a = _b.sent(), statEntry = _a[0], lstatEntry = _a[1];
return [2 /*return*/, {
name: name,
absolutePath: absolutePath,
path: path,
stat: statEntry,
lstat: lstatEntry,
isSymlink: lstatEntry.isSymbolicLink()
}];
}
});
});
async function entryRootFactory(absolutePath, path, name) {
// TODO: make it async?
// const statEntry = fs.statSync(absolutePath);
// const lstatEntry = fs.lstatSync(absolutePath);
const [statEntry, lstatEntry] = await Promise.all([statAsync(absolutePath), lstatAsync(absolutePath)]);
return {
name: name,
absolutePath: absolutePath,
path: path,
stat: statEntry,
lstat: lstatEntry,
isSymlink: lstatEntry.isSymbolicLink()
};
}

@@ -161,5 +108,5 @@ exports.entryRootFactory = entryRootFactory;

function match(fileName, pattern) {
var patternArray = pattern.split(",");
for (var i = 0; i < patternArray.length; i++) {
var pat = patternArray[i];
const patternArray = pattern.split(",");
for (let i = 0; i < patternArray.length; i++) {
const pat = patternArray[i];
if (minimatch_1.default(fileName, pat, { dot: true })) {

@@ -201,4 +148,4 @@ // no case

// http://stackoverflow.com/questions/1179366/is-there-a-javascript-strcmp
var str1 = a.name;
var str2 = b.name;
const str1 = a.name;
const str2 = b.name;
return str1 == str2 ? 0 : str1 > str2 ? 1 : -1;

@@ -220,4 +167,4 @@ }

// http://stackoverflow.com/questions/1179366/is-there-a-javascript-strcmp
var str1 = a.name.toLowerCase();
var str2 = b.name.toLowerCase();
const str1 = a.name.toLowerCase();
const str2 = b.name.toLowerCase();
return str1 == str2 ? 0 : str1 > str2 ? 1 : -1;

@@ -224,0 +171,0 @@ }

@@ -10,11 +10,10 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var BufferPool = /** @class */ (function () {
function BufferPool(size, count) {
var _this = this;
class BufferPool {
constructor(size, count) {
this.bufferPool = [];
// TODO: why was it originally wrapped in a function? That doesn't make
// sense
var createAsyncBuffers = function () {
for (var i = 0; i < count; i++) {
_this.bufferPool.push({
const createAsyncBuffers = () => {
for (let i = 0; i < count; i++) {
this.bufferPool.push({
buf1: Buffer.alloc(size),

@@ -28,5 +27,5 @@ buf2: Buffer.alloc(size),

}
BufferPool.prototype.allocateBuffers = function () {
for (var i = 0, l = this.bufferPool.length; i < l; i++) {
var bufferPair = this.bufferPool[i];
allocateBuffers() {
for (let i = 0, l = this.bufferPool.length; i < l; i++) {
const bufferPair = this.bufferPool[i];
if (!bufferPair.busy) {

@@ -38,9 +37,8 @@ bufferPair.busy = true;

throw new Error("Async buffer limit reached");
};
BufferPool.freeBuffers = function (bufferPair) {
}
static freeBuffers(bufferPair) {
bufferPair.busy = false;
};
return BufferPool;
}());
}
}
exports.default = BufferPool;
//# sourceMappingURL=BufferPool.js.map

@@ -6,4 +6,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var path_1 = __importDefault(require("path"));
var utils_1 = require("../utils");
const path_1 = __importDefault(require("path"));
const utils_1 = require("../utils");
// TODO: maybe pass type1 as param?

@@ -25,3 +25,3 @@ function createLeftOnlyDifference(entry1, level, relativePath) {

date2: undefined,
level: level
level
};

@@ -46,3 +46,3 @@ }

date2: entry2.stat.mtimeMs,
level: level
level
};

@@ -56,3 +56,3 @@ }

path2: path_1.default.dirname(entry2.path),
relativePath: relativePath,
relativePath,
name1: entry1.name,

@@ -68,3 +68,3 @@ name2: entry2.name,

date2: entry2.stat.mtimeMs,
level: level
level
};

@@ -78,3 +78,3 @@ }

path2: path_1.default.dirname(entry2.path),
relativePath: relativePath,
relativePath,
name1: entry1.name,

@@ -90,3 +90,3 @@ name2: entry2.name,

date2: entry2.stat.mtimeMs,
level: level
level
};

@@ -93,0 +93,0 @@ }

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -42,8 +6,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

Object.defineProperty(exports, "__esModule", { value: true });
var fs_1 = __importDefault(require("fs"));
var util_1 = require("util");
var Queue_1 = __importDefault(require("./Queue"));
const fs_1 = __importDefault(require("fs"));
const util_1 = require("util");
const Queue_1 = __importDefault(require("./Queue"));
// const fsOpenAsync = promisify(fs.open);
var fsCloseAsync = util_1.promisify(fs_1.default.close);
var MAX_FILE_DESCRIPTOR_QUEUE_LENGTH = 10000;
const fsCloseAsync = util_1.promisify(fs_1.default.close);
const MAX_FILE_DESCRIPTOR_QUEUE_LENGTH = 10000;
/**

@@ -62,4 +26,4 @@ * Limits the number of concurrent file handlers.

*/
var FileDescriptorQueue = /** @class */ (function () {
function FileDescriptorQueue(maxFilesNo) {
class FileDescriptorQueue {
constructor(maxFilesNo) {
this.pendingJobs = new Queue_1.default(MAX_FILE_DESCRIPTOR_QUEUE_LENGTH);

@@ -69,16 +33,15 @@ this.activeCount = 0;

}
FileDescriptorQueue.prototype.process = function () {
process() {
if (this.pendingJobs.getLength() > 0 && this.activeCount < this.maxFilesNo) {
var job = this.pendingJobs.dequeue();
const job = this.pendingJobs.dequeue();
this.activeCount++;
fs_1.default.open(job.path, job.flags, job.callback);
}
};
FileDescriptorQueue.prototype.open = function (path, flags) {
var _this = this;
return new Promise(function (resolve, reject) {
_this.pendingJobs.enqueue({
path: path,
flags: flags,
callback: function (err, fd) {
}
open(path, flags) {
return new Promise((resolve, reject) => {
this.pendingJobs.enqueue({
path,
flags,
callback: (err, fd) => {
if (err) {

@@ -93,24 +56,13 @@ reject(err);

// Try to process this item or I queue already full, process other results
_this.process();
this.process();
});
};
FileDescriptorQueue.prototype.close = function (fd) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
this.activeCount--;
return [4 /*yield*/, fsCloseAsync(fd)];
case 1:
_a.sent();
// Process next queue items
this.process();
return [2 /*return*/];
}
});
});
};
return FileDescriptorQueue;
}());
}
async close(fd) {
this.activeCount--;
await fsCloseAsync(fd);
// Process next queue items
this.process();
}
}
exports.default = FileDescriptorQueue;
//# sourceMappingURL=FileDescriptorQueue.js.map

@@ -6,4 +6,4 @@ "use strict";

*/
var Queue = /** @class */ (function () {
function Queue(maxUnusedArraySize) {
class Queue {
constructor(maxUnusedArraySize) {
// initialise the queue and offset

@@ -17,5 +17,5 @@ this.queue = [];

// Returns the length of the queue.
Queue.prototype.getLength = function () {
getLength() {
return this.queue.length - this.offset;
};
}
/* Enqueues the specified item. The parameter is:

@@ -25,14 +25,9 @@ *

*/
Queue.prototype.enqueue = function () {
var _a;
var items = [];
for (var _i = 0; _i < arguments.length; _i++) {
items[_i] = arguments[_i];
}
(_a = this.queue).push.apply(_a, items);
};
enqueue(...items) {
this.queue.push(...items);
}
/* Dequeues an item and returns it. If the queue is empty, the value
* 'undefined' is returned.
*/
Queue.prototype.dequeue = function () {
dequeue() {
// if the queue is empty, return immediately

@@ -42,3 +37,3 @@ if (this.queue.length == 0)

// store the item at the front of the queue
var item = this.queue[this.offset];
const item = this.queue[this.offset];
// increment the offset and remove the free space if necessary

@@ -51,6 +46,5 @@ if (++this.offset > this.maxUnusedArraySize) {

return item;
};
return Queue;
}());
}
}
exports.default = Queue;
//# sourceMappingURL=Queue.js.map

@@ -6,15 +6,15 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var Queue_1 = __importDefault(require("./Queue"));
test("Happy path", function () {
const Queue_1 = __importDefault(require("./Queue"));
test("Happy path", () => {
expect.assertions(6);
var queue = new Queue_1.default(100);
const queue = new Queue_1.default(100);
expect(queue.getLength()).toEqual(0);
var item1 = { anyThing: "you want the item to be" };
var item2 = { anyThingReally: "can be queued" };
const item1 = { anyThing: "you want the item to be" };
const item2 = { anyThingReally: "can be queued" };
queue.enqueue(item1, item2);
expect(queue.getLength()).toEqual(2);
var returnedItem1 = queue.dequeue();
const returnedItem1 = queue.dequeue();
expect(returnedItem1).toEqual(item1);
expect(queue.getLength()).toEqual(1);
var returnedItem2 = queue.dequeue();
const returnedItem2 = queue.dequeue();
expect(returnedItem2).toEqual(item2);

@@ -21,0 +21,0 @@ expect(queue.getLength()).toEqual(0);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Statistics = /** @class */ (function () {
function Statistics() {
class Statistics {
constructor() {
this.statistics = {

@@ -28,3 +28,3 @@ total: 0,

}
Statistics.prototype.addDifference = function (difference) {
addDifference(difference) {
this.statistics.total++;

@@ -93,9 +93,8 @@ switch (difference.state) {

}
};
Statistics.prototype.toObject = function () {
}
toObject() {
return this.statistics;
};
return Statistics;
}());
}
}
exports.default = Statistics;
//# sourceMappingURL=Statistics.js.map

@@ -6,5 +6,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var Statistics_1 = __importDefault(require("./Statistics"));
test("No differences", function () {
var statistics = new Statistics_1.default();
const Statistics_1 = __importDefault(require("./Statistics"));
test("No differences", () => {
const statistics = new Statistics_1.default();
expect(statistics.toObject()).toEqual({

@@ -32,4 +32,4 @@ total: 0,

});
test("Add Equal file difference", function () {
var statistics = new Statistics_1.default();
test("Add Equal file difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -72,4 +72,4 @@ path1: "/fake/path-1",

});
test("Add Equal directory difference", function () {
var statistics = new Statistics_1.default();
test("Add Equal directory difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -112,4 +112,4 @@ path1: "/fake/path-1",

});
test("Add Distinct file difference", function () {
var statistics = new Statistics_1.default();
test("Add Distinct file difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -152,4 +152,4 @@ path1: "/fake/path-1",

});
test("Add Distinct directory difference", function () {
var statistics = new Statistics_1.default();
test("Add Distinct directory difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -192,4 +192,4 @@ path1: "/fake/path-1",

});
test("Add Left file difference", function () {
var statistics = new Statistics_1.default();
test("Add Left file difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -232,4 +232,4 @@ path1: "/fake/path-1",

});
test("Add Left directory difference", function () {
var statistics = new Statistics_1.default();
test("Add Left directory difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -272,4 +272,4 @@ path1: "/fake/path-1",

});
test("Add Right file difference", function () {
var statistics = new Statistics_1.default();
test("Add Right file difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -312,4 +312,4 @@ path1: undefined,

});
test("Add Right directory difference", function () {
var statistics = new Statistics_1.default();
test("Add Right directory difference", () => {
const statistics = new Statistics_1.default();
statistics.addDifference({

@@ -316,0 +316,0 @@ path1: undefined,

{
"name": "@renarsvilnis/dir-compare",
"description": "Utility for comparing directories",
"version": "1.0.3",
"version": "1.0.4",
"author": "Renārs Vilnis",

@@ -11,2 +11,5 @@ "keywords": [

],
"engines": {
"node": ">=11.11.0"
},
"license": "MIT",

@@ -20,4 +23,5 @@ "repository": {

},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "src/index.ts",
"mainn": "lib/index.js",
"typess": "lib/index.d.ts",
"files": [

@@ -24,0 +28,0 @@ "lib/**/*",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc