Supersede mkdirp with fs-extra.

Ensure USERS_PATH exists at start.

Remove unnecessary USER_PATH check.

Use fs-extra's copy to write default config.
This commit is contained in:
Daniel 2016-06-09 23:42:23 +01:00
parent 1744b8fb96
commit 3a2d97af6a
5 changed files with 14 additions and 25 deletions

View File

@ -49,7 +49,6 @@
"fs-extra": "0.30.0",
"irc-framework": "2.0.0",
"lodash": "4.11.2",
"mkdirp": "0.5.1",
"moment": "2.13.0",
"read": "1.0.7",
"request": "2.72.0",

View File

@ -1,7 +1,6 @@
var _ = require("lodash");
var fs = require("fs");
var Client = require("./client");
var mkdirp = require("mkdirp");
var Helper = require("./helper");
var oidentd = require("./oidentd");
@ -52,7 +51,6 @@ ClientManager.prototype.loadUser = function(name) {
ClientManager.prototype.getUsers = function() {
var users = [];
mkdirp.sync(Helper.USERS_PATH);
try {
var files = fs.readdirSync(Helper.USERS_PATH);
files.forEach(function(file) {
@ -73,7 +71,6 @@ ClientManager.prototype.addUser = function(name, password) {
return false;
}
try {
mkdirp.sync(Helper.USERS_PATH);
if (require("path").basename(name) !== name) {
throw new Error(name + " is an invalid username.");

View File

@ -1,19 +1,12 @@
var ClientManager = new require("../clientManager");
var bcrypt = require("bcrypt-nodejs");
var program = require("commander");
var mkdirp = require("mkdirp");
var Helper = require("../helper");
program
.command("add <name>")
.description("Add a new user")
.action(function(name/* , password */) {
try {
mkdirp.sync(Helper.USERS_PATH);
} catch (e) {
log.error("Could not create", Helper.USERS_PATH);
return;
}
var manager = new ClientManager();
var users = manager.getUsers();
if (users.indexOf(name) !== -1) {

View File

@ -3,7 +3,7 @@ global.log = require("../log.js");
var program = require("commander");
var pkg = require("../../package.json");
var fs = require("fs");
var mkdirp = require("mkdirp");
var fsextra = require("fs-extra");
var path = require("path");
var Helper = require("../helper");
@ -16,20 +16,20 @@ var argv = program.parseOptions(process.argv);
Helper.setHome(program.home);
if (!fs.existsSync(Helper.CONFIG_PATH)) {
mkdirp.sync(Helper.HOME, {mode: "0700"});
fs.writeFileSync(
Helper.CONFIG_PATH,
fs.readFileSync(path.resolve(path.join(
fsextra.ensureDirSync(Helper.HOME);
fs.chmodSync(Helper.HOME, "0700");
fsextra.copySync(path.resolve(path.join(
__dirname,
"..",
"..",
"defaults",
"config.js"
)))
);
)), Helper.CONFIG_PATH);
log.info("Config created:", Helper.CONFIG_PATH);
}
fsextra.ensureDirSync(Helper.USERS_PATH);
require("./start");
require("./config");
require("./list");

View File

@ -1,12 +1,12 @@
var fs = require("fs");
var mkdirp = require("mkdirp");
var fsextra = require("fs-extra");
var moment = require("moment");
var Helper = require("./helper");
module.exports.write = function(user, network, chan, msg) {
try {
var path = Helper.getUserLogsPath(user, network);
mkdirp.sync(path);
fsextra.ensureDirSync(path);
} catch (e) {
log.error("Unabled to create logs directory", e);
return;