From 7fde7a6b18076e57d20df69910fbbc6f93d66514 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Mon, 30 Sep 2024 02:10:02 -0700 Subject: [PATCH] Don't create directory in erc-truncate compat check * lisp/erc/erc-log.el (erc-log--check-writable-nocreate-p): New variable. (erc-logging-enabled): Use `erc-log--save-in-progress-p' flag to conditionally avoid creating a directory when checking if the location is writable. (erc-log--call-when-logging-enabled-sans-module) (erc-log--check-legacy-implicit-enabling-by-truncate): Rename former to latter, and guard against creating a ~/log directory just to see if it's writable when calling `erc-logging-enabled'. (erc-truncate-mode): Explain legacy "implicit logging" behavior in doc string. * lisp/erc/erc-truncate.el (erc-truncate--warn-about-logging): Make more concise, and defer to `erc-truncate-mode' doc string for particulars. * lisp/erc/erc.el (erc-directory-writable-p): Add comment to rename on next non-patch release. (cherry picked from commit 1de2c86317356dbbf5e7f935d3889b2698bc30f6) --- lisp/erc/erc-log.el | 24 +++++++++++++++--------- lisp/erc/erc-truncate.el | 35 +++++++++++++++++++---------------- lisp/erc/erc.el | 2 ++ 3 files changed, 36 insertions(+), 25 deletions(-) diff --git a/lisp/erc/erc-log.el b/lisp/erc/erc-log.el index 6bb240f56d7..8311359ed09 100644 --- a/lisp/erc/erc-log.el +++ b/lisp/erc/erc-log.el @@ -307,6 +307,10 @@ Return nil if BUFFER is a server buffer." (erc-save-buffer-in-logs buffer))) (defvar erc-log--save-in-progress-p nil) +;; The function `erc-directory-writable-p' may signal when HOME is not +;; writable, such as when running the test suite (/nonexistent). This +;; flag tells `erc-logging-enabled' to use `file-writable-p' instead. +(defvar erc-log--check-writable-nocreate-p nil) ;;;###autoload (defun erc-logging-enabled (&optional buffer) @@ -319,7 +323,9 @@ is writable (it will be created as necessary) and (and erc-log-channels-directory (not erc-log--save-in-progress-p) (or (functionp erc-log-channels-directory) - (erc-directory-writable-p erc-log-channels-directory)) + (if erc-log--check-writable-nocreate-p + (file-writable-p erc-log-channels-directory) + (erc-directory-writable-p erc-log-channels-directory))) (if (functionp erc-enable-logging) (funcall erc-enable-logging buffer) (buffer-local-value 'erc-enable-logging buffer)))) @@ -452,14 +458,14 @@ You can save every individual message by putting this function on (defun erc-log--save-on-clear (_ end) (erc-save-buffer-in-logs end)) -;; This is a kludge to avoid littering erc-truncate.el with forward -;; declarations needed only for a corner-case compatibility check. -(defun erc-log--call-when-logging-enabled-sans-module (fn) - (when (and (erc-logging-enabled) - (not (or erc-log-mode (memq 'log erc-modules)))) - (let ((dirfile (and (stringp erc-log-channels-directory) - erc-log-channels-directory))) - (funcall fn dirfile)))) +;; This exists to avoid littering erc-truncate.el with forward +;; declarations needed only for a compatibility check. +(defun erc-log--check-legacy-implicit-enabling-by-truncate () + "Return non-nil when conditions for legacy \"implicit\" activation are met. +This only concerns the \\+`truncate' module." + (and (not (or erc-log-mode (memq 'log erc-modules))) + (let ((erc-log--check-writable-nocreate-p t)) + (erc-logging-enabled)))) (provide 'erc-log) diff --git a/lisp/erc/erc-truncate.el b/lisp/erc/erc-truncate.el index 393b2af2ba1..fd152707708 100644 --- a/lisp/erc/erc-truncate.el +++ b/lisp/erc/erc-truncate.el @@ -52,7 +52,18 @@ plus `erc-max-buffer-size'." "Truncate a query buffer if it gets too large. This prevents the query buffer from getting too large, which can bring any grown Emacs to its knees after a few days worth of -tracking heavy-traffic channels." +tracking heavy-traffic channels. + +Before ERC 5.6, this module performed logging whenever the \\+`log' +module's library, \\+`erc-log', happened to be loaded, regardless of +whether the \\+`log' module itself was enabled. (Loading can of course +happen in any number of ways, such as when browsing options via +\\[customize-group] or completing autoloaded symbol names at the +\\[describe-variable] prompt.) Users of \\+`truncate' who prefer the +old behavior can add \\+`log' to `erc-modules' to get the same effect. +Those who don't want logging but need to load the \\+`erc-log' library +for other purposes should customize either `erc-enable-logging' or +`erc-log-channels-directory' to avoid the annoying warning." ;;enable ((add-hook 'erc-insert-done-hook #'erc-truncate-buffer) (add-hook 'erc-connect-pre-hook #'erc-truncate--warn-about-logging) @@ -83,21 +94,13 @@ tracking heavy-traffic channels." (defun erc-truncate--warn-about-logging (&rest _) (when (and (not erc--target) - (fboundp 'erc-log--call-when-logging-enabled-sans-module)) - ;; We could also enable `erc-log-mode' here, but the risk of - ;; lasting damage is nonzero. - (erc-log--call-when-logging-enabled-sans-module - (lambda (dirfile) - ;; Emit a real Emacs warning because the message may be - ;; truncated away before it can be read if merely inserted. - (erc-button--display-error-notice-with-keys-and-warn - "The `truncate' module no longer enables logging implicitly." - " If you want ERC to write logs before truncating, add `log' to" - " `erc-modules' using something like \\[customize-option]." - " To silence this message, don't `require' `erc-log'." - (and dirfile " Alternatively, change the value of") - (and dirfile " `erc-log-channels-directory', or move ") - dirfile (and dirfile " elsewhere.")))))) + (fboundp 'erc-log--check-legacy-implicit-enabling-by-truncate) + (erc-log--check-legacy-implicit-enabling-by-truncate)) + ;; Emit a real Emacs warning because the message may be + ;; truncated away before it can be read if merely inserted. + (erc-button--display-error-notice-with-keys-and-warn + "The `truncate' module no longer enables logging implicitly." + " See the doc string for `erc-truncate-mode' for details."))) ;;;###autoload (defun erc-truncate-buffer-to-size (size &optional buffer) diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el index 4b41ede38d6..ed5f239383b 100644 --- a/lisp/erc/erc.el +++ b/lisp/erc/erc.el @@ -9000,6 +9000,8 @@ If S is nil or an empty string then return general CLIENTINFO." ;; Hook functions +;; FIXME rename this to something like `erc-ensure-directory-writable'. +;; Functions suffixed with "-p" probably shouldn't have side effects. (defun erc-directory-writable-p (dir) "Determine whether DIR is a writable directory. If it doesn't exist, create it." -- 2.39.5