diff --git a/core/config_cache.js b/core/config_cache.js index 9df08316..8b57e125 100644 --- a/core/config_cache.js +++ b/core/config_cache.js @@ -6,7 +6,6 @@ var Log = require('./logger.js').log; var paths = require('path'); var fs = require('graceful-fs'); -var Gaze = require('gaze').Gaze; var events = require('events'); var util = require('util'); var assert = require('assert'); @@ -18,7 +17,7 @@ function ConfigCache() { var self = this; this.cache = {}; // filePath -> HJSON - this.gaze = new Gaze(); + //this.gaze = new Gaze(); this.reCacheConfigFromFile = function(filePath, cb) { fs.readFile(filePath, { encoding : 'utf-8' }, function fileRead(err, data) { @@ -32,7 +31,7 @@ function ConfigCache() { }); }; - +/* this.gaze.on('error', function gazeErr(err) { }); @@ -50,6 +49,7 @@ function ConfigCache() { } }); }); + */ } @@ -58,13 +58,13 @@ util.inherits(ConfigCache, events.EventEmitter); ConfigCache.prototype.getConfigWithOptions = function(options, cb) { assert(_.isString(options.filePath)); - var self = this; +// var self = this; var isCached = (options.filePath in this.cache); if(options.forceReCache || !isCached) { this.reCacheConfigFromFile(options.filePath, function fileCached(err, config) { if(!err && !isCached) { - self.gaze.add(options.filePath); + //self.gaze.add(options.filePath); } cb(err, config, true); }); @@ -82,4 +82,4 @@ ConfigCache.prototype.getModConfig = function(fileName, cb) { this.getConfig(paths.join(Config.paths.mods, fileName), cb); }; -module.exports = exports = new ConfigCache(); \ No newline at end of file +module.exports = exports = new ConfigCache(); diff --git a/core/event_scheduler.js b/core/event_scheduler.js index a1c2f6ef..27c68b37 100644 --- a/core/event_scheduler.js +++ b/core/event_scheduler.js @@ -10,8 +10,9 @@ const _ = require('lodash'); const later = require('later'); const path = require('path'); const pty = require('ptyw.js'); -const gaze = require('gaze'); +const sane = require('sane'); const moment = require('moment'); +const paths = require('path'); exports.getModule = EventSchedulerModule; exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart @@ -209,13 +210,13 @@ EventSchedulerModule.prototype.startup = function(cb) { Log.warn( { eventName : schedEvent.name }, 'Invalid scheduled event entry'); return; } - + Log.debug( { eventName : schedEvent.name, schedule : this.moduleConfig.events[schedEvent.name].schedule, action : schedEvent.action, - next : moment(later.schedule(schedEvent.schedule.sched).next(1)).format('ddd, MMM Do, YYYY @ h:m:ss a') + next : schedEvent.schedule.sched ? moment(later.schedule(schedEvent.schedule.sched).next(1)).format('ddd, MMM Do, YYYY @ h:m:ss a') : 'N/A', }, 'Scheduled event loaded' ); @@ -226,12 +227,21 @@ EventSchedulerModule.prototype.startup = function(cb) { }, schedEvent.schedule.sched)); } - if(schedEvent.schedule.watchFile) { - gaze(schedEvent.schedule.watchFile, (err, watcher) => { - // :TODO: should track watched files & stop watching @ shutdown - watcher.on('all', (watchEvent, watchedPath) => { - if(schedEvent.schedule.watchFile === watchedPath) { - self.performAction(schedEvent, `Watch file: ${watchedPath}`); + if(schedEvent.schedule.watchFile) { + const watcher = sane( + paths.dirname(schedEvent.schedule.watchFile), + { + glob : `**/${paths.basename(schedEvent.schedule.watchFile)}` + } + ); + + // :TODO: should track watched files & stop watching @ shutdown? + + [ 'change', 'add', 'delete' ].forEach(event => { + watcher.on(event, (fileName, fileRoot) => { + const eventPath = paths.join(fileRoot, fileName); + if(schedEvent.schedule.watchFile === eventPath) { + self.performAction(schedEvent, `Watch file: ${eventPath}`); } }); }); diff --git a/core/scanner_tossers/ftn_bso.js b/core/scanner_tossers/ftn_bso.js index 7e6e924b..bf1b27a9 100644 --- a/core/scanner_tossers/ftn_bso.js +++ b/core/scanner_tossers/ftn_bso.js @@ -30,7 +30,7 @@ const fs = require('graceful-fs'); const later = require('later'); const temptmp = require('temptmp').createTrackedSession('ftn_bso'); const assert = require('assert'); -const gaze = require('gaze'); +const sane = require('sane'); const fse = require('fs-extra'); const iconv = require('iconv-lite'); const uuidV4 = require('uuid/v4'); @@ -1683,10 +1683,18 @@ FTNMessageScanTossModule.prototype.startup = function(cb) { } if(_.isString(importSchedule.watchFile)) { - gaze(importSchedule.watchFile, (err, watcher) => { - watcher.on('all', (event, watchedPath) => { - if(importSchedule.watchFile === watchedPath) { - tryImportNow(`Performing import/toss due to @watch: ${watchedPath} (${event})`); + const watcher = sane( + paths.dirname(importSchedule.watchFile), + { + glob : `**/${paths.basename(importSchedule.watchFile)}` + } + ); + + [ 'change', 'add', 'delete' ].forEach(event => { + watcher.on(event, (fileName, fileRoot) => { + const eventPath = paths.join(fileRoot, fileName); + if(paths.join(fileRoot, fileName) === importSchedule.watchFile) { + tryImportNow(`Performing import/toss due to @watch: ${eventPath} (${event})`); } }); }); diff --git a/package.json b/package.json index f23ece19..0f86e3d0 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "exiftool": "^0.0.3", "farmhash": "^2.0.4", "fs-extra": "^4.0.1", - "gaze": "^1.1.2", "graceful-fs": "^4.1.11", "hashids": "^1.1.1", "hjson": "^3.1.0", @@ -40,6 +39,7 @@ "node-glob": "^1.2.0", "nodemailer": "^4.1.0", "ptyw.js": "NuSkooler/ptyw.js", + "sane": "^2.2.0", "sanitize-filename": "^1.6.1", "sqlite3": "^3.1.9", "sqlite3-trans" : "^1.2.0",