[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/undo-fu-session 27b688e02d: Add option to skip saving undo
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/undo-fu-session 27b688e02d: Add option to skip saving undo information for temporary files |
Date: |
Sat, 20 May 2023 09:02:55 -0400 (EDT) |
branch: elpa/undo-fu-session
commit 27b688e02d5f5bb7a939f3e312b0219aebe24afc
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Add option to skip saving undo information for temporary files
Bump to version 0.6 as this feature addresses security implications
for utilities that extract encrypted files into a temporary directory
for editing.
Resolves #6.
---
changelog.rst | 3 ++-
readme.rst | 3 +++
undo-fu-session.el | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/changelog.rst b/changelog.rst
index 6d33f3265d..34cbc57e30 100644
--- a/changelog.rst
+++ b/changelog.rst
@@ -3,8 +3,9 @@
Change Log
##########
-- In development.
+- Version 0.6 (2023-05-20)
+ - Add ``undo-fu-session-ignore-temp-files`` to ignore files in temporary
directories.
- The ``undo-fu-session-incompatible-files`` match is now case insensitive
for case insensitive file-systems.
- Version 0.5 (2023-04-05)
diff --git a/readme.rst b/readme.rst
index 322c4afa78..451dc3f19a 100644
--- a/readme.rst
+++ b/readme.rst
@@ -80,6 +80,9 @@ Customization
List of major-modes in which saving undo session should not be performed.
``undo-fu-session-ignore-encrypted-files`` (``t``)
Ignore saving/recovering undo session for encrypted files (matching
``epa-file-name-regexp``).
+``undo-fu-session-ignore-temp-files`` (``t``)
+ Ignore saving/recovering undo session for files under
``temporary-file-directory``
+ (as well as ``/tmp`` & ``/dev/shm/``).
``undo-fu-session-file-limit`` (``nil``)
Number of files to store, nil to disable limiting entirely.
diff --git a/undo-fu-session.el b/undo-fu-session.el
index 158538dbc3..30443466fc 100755
--- a/undo-fu-session.el
+++ b/undo-fu-session.el
@@ -8,7 +8,7 @@
;; URL: https://codeberg.com/ideasman42/emacs-undo-fu-session
;; Keywords: convenience
-;; Version: 0.5
+;; Version: 0.6
;; Package-Requires: ((emacs "28.1"))
;;; Commentary:
@@ -64,6 +64,10 @@
"Ignore encrypted files for undo session."
:type 'boolean)
+(defcustom undo-fu-session-ignore-temp-files t
+ "Ignore temporary files for undo session."
+ :type 'boolean)
+
(defcustom undo-fu-session-compression 'gz
"The type of compression to use or nil.
@@ -101,6 +105,30 @@ Enforcing removes the oldest files."
`(let ((inhibit-message t))
(message ,str ,@args)))
+(defun undo-fu-session--canonicalize-path (path)
+ "Return the canonical PATH.
+
+This is done without adjusting trailing slashes or following links."
+ ;; Some pre-processing on `path' since it may contain the user path
+ ;; or be relative to the default directory.
+ ;;
+ ;; Notes:
+ ;; - This is loosely based on `f-same?'` from the `f' library.
+ ;; However it's important this only runs on the user directory and NOT
trusted directories
+ ;; since there should never be any ambiguity (which could be caused by
expansion)
+ ;; regarding which path is trusted.
+ ;; - Avoid `file-truename' since this follows symbolic-links,
+ ;; `expand-file-name' handles `~` and removing `/../' from paths.
+ (let ((file-name-handler-alist nil))
+ ;; Expand user `~' and default directory.
+ (expand-file-name path)))
+
+(defun undo-fu-session--ensure-trailing-slash (dir)
+ "Return DIR with exactly one trailing slash."
+ ;; Both "/tmp" and "/tmp//" result in "/tmp/"
+ (file-name-as-directory (directory-file-name dir)))
+
+
;; ---------------------------------------------------------------------------
;; Undo List Make Linear
;;
@@ -449,6 +477,34 @@ Argument PENDING-LIST an `pending-undo-list' compatible
list."
(funcall matcher filename)))
(throw 'found t))))))
+(defun undo-fu-session--temp-file-check (filename)
+ "Return t if FILENAME is in a temporary directory."
+ (let ((temp-dirs (list))
+ (is-temp nil))
+ (when temporary-file-directory
+ ;; Ensure a single slash so `string-prefix-p' can be used.
+ (push (undo-fu-session--ensure-trailing-slash temporary-file-directory)
temp-dirs))
+
+ ;; Even if this directory doesn't exist, the check is relatively harmless.
+ (cond
+ ((memq system-type (list 'ms-dos 'windows-nt))
+ nil)
+ (t
+ (push "/tmp/" temp-dirs)
+ (push "/dev/shm/" temp-dirs)))
+
+ (setq temp-dirs (delete-dups temp-dirs))
+
+ (when temp-dirs
+ ;; Canonicalized in case the default directory happens to be TEMP.
+ (let ((filename-canonical (undo-fu-session--canonicalize-path filename)))
+ (while temp-dirs
+ (let ((dir (pop temp-dirs)))
+ (when (string-prefix-p dir filename-canonical
(file-name-case-insensitive-p dir))
+ (setq is-temp t)
+ (setq temp-dirs nil))))))
+ is-temp))
+
(defun undo-fu-session--directory-ensure ()
"Ensure the undo directory has been created."
(unless (file-directory-p undo-fu-session-directory)
@@ -469,6 +525,8 @@ Argument PENDING-LIST an `pending-undo-list' compatible
list."
epa-file-handler
(string-match-p (car epa-file-handler) filename))
nil)
+ ((and undo-fu-session-ignore-temp-files (undo-fu-session--temp-file-check
filename))
+ nil)
((and test-files (undo-fu-session--match-file-name filename test-files))
nil)
((and test-modes (memq (buffer-local-value 'major-mode buffer)
test-modes))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/undo-fu-session 27b688e02d: Add option to skip saving undo information for temporary files,
ELPA Syncer <=