erc-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Erc-commit] [commit][emacs22] erc-log: Make log file names safe.


From: mwolson
Subject: [Erc-commit] [commit][emacs22] erc-log: Make log file names safe.
Date: Sun, 14 Oct 2007 00:48:23 -0400

commit df12cd4ddd24875b5041201120dfa0dc35bec468
Author: Michael Olson <address@hidden>
Date:   Sat Aug 5 23:52:52 2006 +0000

    erc-log: Make log file names safe.
    
    * erc-log.el (erc-log-standardize-name): New function that returns a
      filename that is safe for use for a log file.
      (erc-current-logfile): Use it.
    git-archimport-id: address@hidden/erc--main--0--patch-31

diff --git a/ChangeLog b/ChangeLog
index 67d944d..0d54e14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2006-08-05  Michael Olson  <address@hidden>
 
+       * erc-log.el (erc-log-standardize-name): New function that returns
+       a filename that is safe for use for a log file.
+       (erc-current-logfile): Use it.
+
        * erc.el (erc-startup-file-list): Search in ~/.emacs.d first,
        since that is a fairly standard directory.
        (erc-select-startup-file): Re-write to use
diff --git a/erc-log.el b/erc-log.el
index 78fab79..32924e6 100644
--- a/erc-log.el
+++ b/erc-log.el
@@ -71,8 +71,6 @@
 ;; markers.
 
 ;;; TODO:
-;; * Erc needs a generalised make-safe-file-name function, so that
-;;   generated file names don't contain any invalid file characters.
 ;;
 ;; * Really, we need to lock the logfiles somehow, so that if a user
 ;;   is running multiple emacsen and/or on the same channel as more
@@ -299,17 +297,27 @@ is writeable (it will be created as necessary) and
           (funcall erc-enable-logging (or buffer (current-buffer)))
         erc-enable-logging)))
 
+(defun erc-log-standardize-name (filename)
+  "Make FILENAME safe to use as the name of an ERC log.
+This will not work with full paths, only names.
+
+Any unsafe characters in the name are replaced with \"!\".  The
+filename is downcased."
+  (downcase (erc-replace-regexp-in-string
+            "[/\\]" "!" (convert-standard-filename filename))))
+
 (defun erc-current-logfile (&optional buffer)
   "Return the logfile to use for BUFFER.
 If BUFFER is nil, the value of `current-buffer' is used.
 This is determined by `erc-generate-log-file-name-function'.
 The result is converted to lowercase, as IRC is case-insensitive"
   (expand-file-name
-   (downcase (funcall erc-generate-log-file-name-function
-                     (or buffer (current-buffer))
-                     (or (erc-default-target) (buffer-name buffer))
-                     (erc-current-nick)
-                     erc-session-server erc-session-port))
+   (erc-log-standardize-name
+    (funcall erc-generate-log-file-name-function
+            (or buffer (current-buffer))
+            (or (erc-default-target) (buffer-name buffer))
+            (erc-current-nick)
+            erc-session-server erc-session-port))
    erc-log-channels-directory))
 
 (defun erc-generate-log-file-name-with-date (buffer &rest ignore)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]