From 3a2d97af6a9db4b5cfc5f9156fc706210d6faa2f Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Jun 2016 23:42:23 +0100 Subject: [PATCH] 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. --- package.json | 1 - src/clientManager.js | 3 --- src/command-line/add.js | 7 ------- src/command-line/index.js | 24 ++++++++++++------------ src/userLog.js | 4 ++-- 5 files changed, 14 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 5a6362f3..b1dd3446 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/clientManager.js b/src/clientManager.js index 420d4bf2..bd1142bb 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -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."); diff --git a/src/command-line/add.js b/src/command-line/add.js index d4c47124..fc5f8265 100644 --- a/src/command-line/add.js +++ b/src/command-line/add.js @@ -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 ") .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) { diff --git a/src/command-line/index.js b/src/command-line/index.js index d81988bb..236c390c 100644 --- a/src/command-line/index.js +++ b/src/command-line/index.js @@ -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( - __dirname, - "..", - "..", - "defaults", - "config.js" - ))) - ); + 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"); diff --git a/src/userLog.js b/src/userLog.js index c2805dc6..8bb3e6d5 100644 --- a/src/userLog.js +++ b/src/userLog.js @@ -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;