emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/undo-fu-session 36e3bbabfa 51/53: Always ensure the target


From: ELPA Syncer
Subject: [nongnu] elpa/undo-fu-session 36e3bbabfa 51/53: Always ensure the target directory exists before saving
Date: Thu, 7 Jul 2022 12:05:31 -0400 (EDT)

branch: elpa/undo-fu-session
commit 36e3bbabfa5dfb8f157bf557575ed5fda60d66df
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>

    Always ensure the target directory exists before saving
    
    Unlikely this is ever needed, more of a sanity check as it's
    possible the user removes the directory after the mode is enabled.
---
 undo-fu-session.el | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/undo-fu-session.el b/undo-fu-session.el
index 80d7569688..17e7679835 100755
--- a/undo-fu-session.el
+++ b/undo-fu-session.el
@@ -458,6 +458,13 @@ Argument PENDING-LIST an `pending-undo-list' compatible 
list."
             (funcall matcher filename)))
         (throw 'found t)))))
 
+(defun undo-fu-session--directory-ensure ()
+  (unless (file-directory-p undo-fu-session-directory)
+    (make-directory undo-fu-session-directory t)
+    ;; These files should only readable by the owner, see #2.
+    ;; Setting the executable bit is important for directories to be writable.
+    (set-file-modes undo-fu-session-directory #o700)))
+
 (defun undo-fu-session--recover-buffer-p (buffer)
   "Return t if undo data of BUFFER should be recovered."
   (let
@@ -483,6 +490,10 @@ Argument PENDING-LIST an `pending-undo-list' compatible 
list."
 
 (defun undo-fu-session--save-impl ()
   "Internal save logic, resulting in t on success."
+
+  ;; Paranoid as it's possible the directory was removed since the mode was 
enabled.
+  (undo-fu-session--directory-ensure)
+
   (let
     (
       (buffer (current-buffer))
@@ -692,11 +703,10 @@ Argument PENDING-LIST an `pending-undo-list' compatible 
list."
 
 (defun undo-fu-session-mode-enable ()
   "Turn on 'undo-fu-session-mode' for the current buffer."
-  (unless (file-directory-p undo-fu-session-directory)
-    (make-directory undo-fu-session-directory t)
-    ;; These files should only readable by the owner, see #2.
-    ;; Setting the executable bit is important for directories to be writable.
-    (set-file-modes undo-fu-session-directory #o700))
+  ;; Even though this runs on save, call here since it's better the user 
catches
+  ;; errors when the mode is enabled instead of having the hook fail.
+  (undo-fu-session--directory-ensure)
+
   (add-hook 'write-file-functions #'undo-fu-session-save-safe)
   (add-hook 'find-file-hook #'undo-fu-session-recover-safe))
 



reply via email to

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