emacs-diffs
[Top][All Lists]
Advanced

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

master 6cffaa3b6d 2/3: image-dired: End thumbnail file names with ".jpg"


From: Stefan Kangas
Subject: master 6cffaa3b6d 2/3: image-dired: End thumbnail file names with ".jpg"
Date: Wed, 28 Sep 2022 06:42:33 -0400 (EDT)

branch: master
commit 6cffaa3b6daf767808a9d9ae549fc2aea5c5c07e
Author: Stefan Kangas <stefankangas@gmail.com>
Commit: Stefan Kangas <stefankangas@gmail.com>

    image-dired: End thumbnail file names with ".jpg"
    
    * lisp/image/image-dired-util.el (image-dired-thumb-name): Always
    end thumbnail name in ".jpg" and simplify naming to just use the
    SHA-1 hash.  (Bug#57961)
    * test/lisp/image/image-dired-util-tests.el
    (image-dired-thumb-name/image-dired): Adjust test for the above
    change.
    * etc/NEWS: Announce the above change.
---
 etc/NEWS                                  |  9 ++++++
 lisp/image/image-dired-util.el            | 53 +++++++++++++------------------
 test/lisp/image/image-dired-util-tests.el |  7 ++--
 3 files changed, 36 insertions(+), 33 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 99243481a0..b85975944a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2218,6 +2218,15 @@ nil to disable this confirmation completely.
 +++
 *** 'image-dired-db-file' renamed to 'image-dired-tags-db-file'.
 
+---
+*** Naming of thumbnail files has changed.
+Thumbnail files generated when 'image-dired-thumbnail-storage' is
+'image-dired' now always end in ".jpg".  This fixes various issues on
+different platforms, but means that thumbnails generated in Emacs 28
+will not be used in Emacs 29, and vice-versa.  If disk space is an
+issue, consider deleting the directory 'image-dired-dir' after
+upgrading (usually "~/.emacs.d/image-dired/").
+
 ---
 *** 'image-dired-thumb-{height,width}' are now obsolete.
 Customize 'image-dired-thumb-size' instead, which will set both the
diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el
index e7d116d90b..dd746886a4 100644
--- a/lisp/image/image-dired-util.el
+++ b/lisp/image/image-dired-util.el
@@ -70,37 +70,28 @@ file name of the thumbnail will vary:
   of the image file's directory name will be added to the
   filename.
 See also `image-dired-thumbnail-storage'."
-  (cond ((memq image-dired-thumbnail-storage
-               image-dired--thumbnail-standard-sizes)
-         (let ((thumbdir (cl-case image-dired-thumbnail-storage
-                           (standard "thumbnails/normal")
-                           (standard-large "thumbnails/large")
-                           (standard-x-large "thumbnails/x-large")
-                           (standard-xx-large "thumbnails/xx-large"))))
-           (expand-file-name
-            ;; MD5 is mandated by the Thumbnail Managing Standard.
-            (concat (md5 (concat "file://" (expand-file-name file))) ".png")
-            (expand-file-name thumbdir (xdg-cache-home)))))
-        ((or (eq 'image-dired image-dired-thumbnail-storage)
-             ;; Maintained for backwards compatibility:
-             (eq 'use-image-dired-dir image-dired-thumbnail-storage))
-         (let* ((f (expand-file-name file))
-                (hash (md5 (file-name-as-directory (file-name-directory f)))))
-           (expand-file-name
-            (format "%s%s.thumb.%s"
-                    (file-name-base f)
-                    (if hash (concat "_" hash) "")
-                    (file-name-extension f))
-            (image-dired-dir))))
-        ((eq 'per-directory image-dired-thumbnail-storage)
-         (let ((f (expand-file-name file)))
-           (expand-file-name
-            (format "%s.thumb.%s"
-                    (file-name-base f)
-                    (file-name-extension f))
-            (expand-file-name
-             ".image-dired"
-             (file-name-directory f)))))))
+  (let ((file (expand-file-name file)))
+    (cond ((memq image-dired-thumbnail-storage
+                 image-dired--thumbnail-standard-sizes)
+           (let ((thumbdir (cl-case image-dired-thumbnail-storage
+                             (standard "thumbnails/normal")
+                             (standard-large "thumbnails/large")
+                             (standard-x-large "thumbnails/x-large")
+                             (standard-xx-large "thumbnails/xx-large"))))
+             (expand-file-name
+              ;; MD5 is mandated by the Thumbnail Managing Standard.
+              (concat (md5 (concat "file://" file)) ".png")
+              (expand-file-name thumbdir (xdg-cache-home)))))
+          ((or (eq 'image-dired image-dired-thumbnail-storage)
+               ;; Maintained for backwards compatibility:
+               (eq 'use-image-dired-dir image-dired-thumbnail-storage))
+           (expand-file-name (format "%s.jpg" (sha1 file))
+                             (image-dired-dir)))
+          ((eq 'per-directory image-dired-thumbnail-storage)
+           (expand-file-name (format "%s.thumb.jpg" file)
+                             (expand-file-name
+                              ".image-dired"
+                              (file-name-directory file)))))))
 
 (defvar image-dired-thumbnail-buffer "*image-dired*"
   "Image-Dired's thumbnail buffer.")
diff --git a/test/lisp/image/image-dired-util-tests.el 
b/test/lisp/image/image-dired-util-tests.el
index 9fb457dd36..cd371ef61a 100644
--- a/test/lisp/image/image-dired-util-tests.el
+++ b/test/lisp/image/image-dired-util-tests.el
@@ -48,9 +48,12 @@
                (file-name-directory (image-dired-thumb-name "foo.jpg"))
                (file-name-directory (image-dired-thumb-name "/tmp/foo.jpg"))))
       (should (equal (file-name-nondirectory
-                      ;; The checksum is based on the directory name.
+                      ;; The checksum is based on the file name.
                       (image-dired-thumb-name "/some/path/foo.jpg"))
-                     "foo_45fff7fcc4a0945679b7b11dec36a82d.thumb.jpg")))))
+                     "dc4e6f7068157023e7f2e8362d15bdd2e3ca89e4.jpg"))
+      (should (equal (file-name-extension
+                      (image-dired-thumb-name "foo.gif"))
+                     "jpg")))))
 
 (ert-deftest image-dired-thumb-name/per-directory ()
   (let ((image-dired-thumbnail-storage 'per-directory))



reply via email to

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