ilastlog
Version:
alternative lastlog because of Ubuntu 24.04.1. The distros have had the libpam excluding lastlog.so. therefore, I personally needed.
63 lines • 2.54 kB
JavaScript
;
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 __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.appendFile = appendFile;
exports.appendFileAsync = appendFileAsync;
const load_json_file_1 = require("load-json-file");
const write_json_file_1 = require("write-json-file");
const promises_1 = require("node:fs/promises");
const node_fs_1 = require("node:fs");
const node_path_1 = __importDefault(require("node:path"));
const env_paths_1 = __importDefault(require("env-paths"));
const fileName = "lastlog.json";
const paths = (0, env_paths_1.default)("ilastlog");
const basePath = node_path_1.default.join(paths.data, fileName);
const mode = 0o666;
function appendFile(newData) {
let data = {};
try {
(0, node_fs_1.accessSync)(basePath, promises_1.constants.F_OK);
data = (0, load_json_file_1.loadJsonFileSync)(basePath, {});
}
catch (err) {
data = {};
}
data = Object.assign(data, newData);
try {
(0, write_json_file_1.writeJsonFileSync)(basePath, data);
}
catch (err) {
throw new Error("Failed to Write:" + err);
}
}
function appendFileAsync(newData) {
return __awaiter(this, void 0, void 0, function* () {
let data = {};
try {
yield (0, promises_1.access)(basePath, promises_1.constants.F_OK);
data = (yield (0, load_json_file_1.loadJsonFile)(basePath, {}));
}
catch (error) {
data = {};
}
data = Object.assign(data, newData);
try {
yield (0, write_json_file_1.writeJsonFile)(basePath, data);
}
catch (error) {
throw new Error("Failed to Write:" + error);
}
});
}
//# sourceMappingURL=fileManger.js.map