]> git.eshelyaron.com Git - emacs.git/commitdiff
Don't create directory in erc-truncate compat check
authorF. Jason Park <jp@neverwas.me>
Mon, 30 Sep 2024 09:10:02 +0000 (02:10 -0700)
committerEshel Yaron <me@eshelyaron.com>
Mon, 14 Oct 2024 17:38:31 +0000 (19:38 +0200)
* 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
lisp/erc/erc-truncate.el
lisp/erc/erc.el

index 6bb240f56d79244893149dc39779bdc1df3df578..8311359ed09eb8b9b739cf7306276a0f6da27627 100644 (file)
@@ -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)
 
index 393b2af2ba16df310b271cf496d0848cac2087d1..fd152707708ad62360c1684397d811505af89cd2 100644 (file)
@@ -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)
index 4b41ede38d6e703d0670ad109bb72d0af5692d99..ed5f239383b7c69de2d76a6a074e783640433315 100644 (file)
@@ -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."