* Ability to save off imported (and later, exported) packets for debugging purposes via scannerTossers::ftn_bso::retainImportPacketPath config.hjson opt

This commit is contained in:
Bryan Ashby 2016-04-13 21:06:27 -06:00
parent f0919b5227
commit 7278450d9e
1 changed files with 53 additions and 26 deletions

View File

@ -2,26 +2,26 @@
'use strict'; 'use strict';
// ENiGMA½ // ENiGMA½
let MessageScanTossModule = require('../msg_scan_toss_module.js').MessageScanTossModule; const MessageScanTossModule = require('../msg_scan_toss_module.js').MessageScanTossModule;
let Config = require('../config.js').config; const Config = require('../config.js').config;
let ftnMailPacket = require('../ftn_mail_packet.js'); const ftnMailPacket = require('../ftn_mail_packet.js');
let ftnUtil = require('../ftn_util.js'); const ftnUtil = require('../ftn_util.js');
let Address = require('../ftn_address.js'); const Address = require('../ftn_address.js');
let Log = require('../logger.js').log; const Log = require('../logger.js').log;
let ArchiveUtil = require('../archive_util.js'); const ArchiveUtil = require('../archive_util.js');
let msgDb = require('../database.js').dbs.message; const msgDb = require('../database.js').dbs.message;
let Message = require('../message.js'); const Message = require('../message.js');
let moment = require('moment'); const moment = require('moment');
let _ = require('lodash'); const _ = require('lodash');
let paths = require('path'); const paths = require('path');
let async = require('async'); const async = require('async');
let fs = require('fs'); const fs = require('fs');
let later = require('later'); const later = require('later');
let temp = require('temp').track(); // track() cleans up temp dir/files for us const temp = require('temp').track(); // track() cleans up temp dir/files for us
let assert = require('assert'); const assert = require('assert');
let gaze = require('gaze'); const gaze = require('gaze');
let fse = require('fs-extra'); const fse = require('fs-extra');
exports.moduleInfo = { exports.moduleInfo = {
name : 'FTN BSO', name : 'FTN BSO',
@ -53,8 +53,6 @@ function FTNMessageScanTossModule() {
if(_.has(Config, 'scannerTossers.ftn_bso')) { if(_.has(Config, 'scannerTossers.ftn_bso')) {
this.moduleConfig = Config.scannerTossers.ftn_bso; this.moduleConfig = Config.scannerTossers.ftn_bso;
} }
this.getDefaultNetworkName = function() { this.getDefaultNetworkName = function() {
@ -926,6 +924,23 @@ function FTNMessageScanTossModule() {
}); });
}; };
this.archivePacketFile = function(type, origPath, label, cb) {
if('import' === type && _.isString(self.moduleConfig.retainImportPacketPath)) {
const archivePath = paths.join(
self.moduleConfig.retainImportPacketPath,
`${label}-${moment().format('YYYY-MM-DDTHH.mm.ss.SSS')}-${paths.basename(origPath)}`);
fse.copy(origPath, archivePath, err => {
if(err) {
Log.warn( { origPath : origPath, archivePath : archivePath }, 'Failed to archive packet file');
}
cb(null); // non-fatal always
});
} else {
cb(null); // NYI
}
}
this.importPacketFilesFromDirectory = function(importDir, password, cb) { this.importPacketFilesFromDirectory = function(importDir, password, cb) {
async.waterfall( async.waterfall(
[ [
@ -958,13 +973,25 @@ function FTNMessageScanTossModule() {
function handleProcessedFiles(packetFiles, rejects, callback) { function handleProcessedFiles(packetFiles, rejects, callback) {
async.each(packetFiles, (packetFile, nextFile) => { async.each(packetFiles, (packetFile, nextFile) => {
const fullPath = paths.join(importDir, packetFile); const fullPath = paths.join(importDir, packetFile);
//
// If scannerTossers::ftn_bso::reainImportPacketPath is set,
// copy each packet file over in the following format:
//
// <good|bad>-<msSinceEpoc>-<origPacketFileName.pkt>
//
if(rejects.indexOf(packetFile) > -1) { if(rejects.indexOf(packetFile) > -1) {
// :TODO: rename to .bad, perhaps move to a rejects dir + log self.archivePacketFile('import', fullPath, 'reject', () => {
nextFile(); nextFile();
});
// :TODO: rename to .bad, perhaps move to a rejects dir + log
//nextFile();
} else { } else {
self.archivePacketFile('import', fullPath, 'imported', () => {
fs.unlink(fullPath, err => { fs.unlink(fullPath, err => {
nextFile(); nextFile();
}); });
});
} }
}, err => { }, err => {
callback(err); callback(err);