Skip to content

Commit

Permalink
Clean up bin/haraka (#2088)
Browse files Browse the repository at this point in the history
* Remove unused folders from installation
* Use mkdirp in queue/quarantine
  • Loading branch information
KingNoosh authored and msimerson committed Sep 10, 2017
1 parent e5465f9 commit b0d60d1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
7 changes: 5 additions & 2 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
* Permit log settings to be set w/o LOG prefix #2057
* additional results storing in smtp_forward and quarantine #2067
* smtp_forward stores queue note at queue.wants #2083
* Remove unused folders from installation #2088
* New Features
* TLS certificate directory (config/tls) #2032
* plugins can specify a queue plugin & next_hop route #2067
* connection/transaction notes now have get/set #2082
* Fixes
* haraka cli will now create folders if they don't exist #2088

## 2.8.14 - Jul 26, 2017

Expand Down Expand Up @@ -375,7 +378,7 @@
* removed TLD stuff to haraka/haraka-tld (#1301)
* removed unused 'require('redis') in plugins/karma (#1348)
* improved MIME header support per rfc2231 (#1344)
* tls options can be defined for outbound and smtp\_\* (#1357)
* tls options can be defined for outbound and smtp\_\* (#1357)
* explicitly disable SSLv2 (#1395)
* cache STUN results
* xclient plugin improvements (#1405)
Expand Down Expand Up @@ -427,7 +430,7 @@
* connection: pause for hook_reset_transaction (#1303)
* rcpt_to.routes: update redis usage for compat with redis plugin (#1302)
* smtp_forward: use correct config path to auth settings (#1327)
* messagestream: correctly pass options parameter to get_data (#1316)
* messagestream: correctly pass options parameter to get_data (#1316)
* spf: honour configuration for mfrom scope (#1322)
* outbound: Add missing dash to 'Final-Recipient' header name (#1320)

Expand Down
13 changes: 7 additions & 6 deletions bin/haraka
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var nopt = require('nopt');
var os = require('os');

var utils = require('haraka-utils');
var mkdirp = require('mkdirp');
var sprintf = require('sprintf-js').sprintf;
var base = path.join(__dirname, '..');
var ver = JSON.parse(fs.readFileSync(base+'/package.json', 'utf8')).version;
Expand Down Expand Up @@ -113,7 +114,7 @@ var listPlugins = function (b, dir) {

// Show message when create
function create (dirPath) {
// console.log('\x1b[32mcreate\x1b[0m: ' + dirPath);
console.log('\x1b[32mcreate\x1b[0m: ' + dirPath);
}

// Warning messsage
Expand All @@ -134,7 +135,7 @@ function mkDir (dstPath) {
catch (ignore) {}

try {
fs.mkdirSync(dstPath, fs.statSync(__dirname).mode);
mkdirp.sync(dstPath);
create(dstPath)
}
catch (e) {
Expand Down Expand Up @@ -193,6 +194,7 @@ function copyFile (srcFile, dstFile) {
catch (e) {
// File NOT exists
if (e.code == 'ENOENT') {
mkDir(path.dirname(dstFile));
fs.writeFileSync(dstFile, fs.readFileSync(srcFile));
create(dstFile)
}
Expand All @@ -204,6 +206,7 @@ function copyFile (srcFile, dstFile) {
}

function setupHostname (confPath) {
mkDir(confPath);
var hlPath = path.join(confPath, 'host_list');
try {
if (fs.statSync(hlPath).isFile()) return;
Expand Down Expand Up @@ -260,7 +263,7 @@ var packageJson = JSON.stringify({
"dependencies": {},
"repository": "",
"license": "MIT"
});
}, null, 2);

var plugin_src = [
"// %plugin%",
Expand Down Expand Up @@ -290,6 +293,7 @@ function createFile (filePath, data, info) {
if (fs.existsSync(filePath) && !parsed.force) {
throw filePath + " already exists";
}
mkDir(path.dirname(filePath));
var fd = fs.openSync(filePath, 'w');
var output = data.replace(/\%(\w+)\%/g, function (i, m1) { return info[m1] });
fs.writeSync(fd, output, null);
Expand Down Expand Up @@ -654,10 +658,7 @@ else if (parsed.install) {
var pa = parsed.install;
mkDir(parsed.install);
mkDir(path.join(pa, 'plugins'));
mkDir(path.join(pa, 'plugins/auth'));
mkDir(path.join(pa, 'docs'));
mkDir(path.join(pa, 'docs/plugins'));
mkDir(path.join(pa, 'docs/plugins/auth'));
mkDir(path.join(pa, 'config'));
createFile(path.join(pa, 'README'), readme);
createFile(path.join(pa, 'package.json'), packageJson);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"haraka-results" : "^2.0.0",
"haraka-utils" : "*",
"haraka-plugin-access" : "*",
"haraka-plugin-limit" : "*"
"haraka-plugin-limit" : "*",
"mkdirp" : "~0.5.1"
},
"optionalDependencies": {
"haraka-plugin-asn" : "*",
Expand Down
23 changes: 11 additions & 12 deletions plugins/queue/quarantine.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');

exports.register = function () {
const plugin = this;
Expand All @@ -23,16 +24,6 @@ exports.load_quarantine_ini = function () {
})
}

// http://unknownerror.net/2011-05/16260-nodejs-mkdirs-recursion-create-directory.html
var mkdirs = exports.mkdirs = function (dirpath, mode, callback) {
if (fs.existsSync(dirpath)) {
return callback(dirpath);
}
mkdirs(path.dirname(dirpath), mode, function () {
fs.mkdir(dirpath, mode, callback);
});
};

var zeroPad = exports.zeroPad = function (n, digits) {
n = n.toString();
while (n.length < digits) {
Expand Down Expand Up @@ -77,7 +68,10 @@ exports.get_base_dir = function () {
exports.init_quarantine_dir = function (done) {
const plugin = this;
const tmp_dir = path.join(plugin.get_base_dir(), 'tmp');
mkdirs(tmp_dir, parseInt('0770', 8), function () {
mkdirp(tmp_dir, function (err) {
if (err) {
plugin.logerror(`Unable to create ${tmp_dir}`);
}
plugin.loginfo(`created ${tmp_dir}`);
done();
});
Expand Down Expand Up @@ -113,7 +107,12 @@ exports.quarantine = function (next, connection) {
// successful we hardlink the file to the final destination and then
// remove the temporary file to guarantee a complete file in the
// final destination.
mkdirs(msg_dir, parseInt('0770', 8), function () {
mkdirp(msg_dir, function (error) {
if (error) {
connection.logerror(plugin, 'Error creating directory: ' + msg_dir);
return next();
}

const ws = fs.createWriteStream(tmp_path);

ws.on('error', function (err) {
Expand Down

0 comments on commit b0d60d1

Please sign in to comment.