cross-process-lock
Version:
Cross-process file locking solution with lock-queue
36 lines • 1.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.unlock = unlock;
const tslib_1 = require("tslib");
const node_fs_1 = require("node:fs");
const logger_1 = require("./logger");
const metadata_1 = require("./metadata");
/**
* Releases the cross-process lock for the given file, for the actual process.
*
* @param file The path of the file to lock.
* @returns
*/
function unlock(file) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
(0, logger_1.logger)("unlock file:%s", file);
const lockFile = `${file}.lock`;
if (!(0, node_fs_1.existsSync)(lockFile)) {
(0, logger_1.logger)("unlock lock file does not exist");
return;
}
const metadata = yield (0, metadata_1.readMetadata)(lockFile);
if (!metadata || metadata.pID === process.pid) {
try {
(0, node_fs_1.unlinkSync)(lockFile);
}
catch (e) {
(0, logger_1.logger)("unlock error during deleting lock file:%s", e);
}
}
else {
(0, logger_1.logger)("unlock foreign lock file");
}
});
}
//# sourceMappingURL=unlock.js.map