haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.09k stars 661 forks source link

Allow absolute paths in config.get #1769

Closed gramakri closed 7 years ago

gramakri commented 7 years ago

I would like to use the existing config.get and configfile watcher mechanism to read plugin configuration. This plugin configuration is located outside Haraka's config directory. The file config is loaded as expected but the file watcher fails because Haraka only watches the config file directory.

Would you be open to adding support for this in configfile.js?

gramakri commented 7 years ago

Untested patch:

diff --git a/configfile.js b/configfile.js
index c2e7c51..3315bb1 100644
--- a/configfile.js
+++ b/configfile.js
@@ -79,9 +79,9 @@ cfreader.on_watch_event = function (name, type, options, cb) {
     };
 };

-cfreader.watch_dir = function () {
+cfreader.watch_dir = function (name) {
     // NOTE: This only works on Linux and Windows
-    var cp = cfreader.config_path;
+    var cp = path.isAbsolute(name) ? path.dirname(name) : cfreader.config_path;
     if (cfreader._watchers[cp]) return;
     var watcher = function (fse, filename) {
         if (!filename) return;
@@ -192,7 +192,7 @@ cfreader.read_config = function(name, type, cb, options) {
         case 'win32':
         case 'win64':
         case 'linux':
-            cfreader.watch_dir();
+            cfreader.watch_dir(name);
             break;
         default:
             // All other operating systems
msimerson commented 7 years ago

In this case, you're effectively disabling watching the configs in Haraka's directory and watching some other directory instead. If I'm reading your patch correctly? Is that the desired result?

gramakri commented 7 years ago

I will close this for now since I don't remember what this was about. Sorry.