]> git.eshelyaron.com Git - emacs.git/commitdiff
Make image-dired-thumb-name more portable
authorStefan Kangas <stefankangas@gmail.com>
Sun, 25 Sep 2022 12:22:06 +0000 (14:22 +0200)
committerStefan Kangas <stefankangas@gmail.com>
Sun, 25 Sep 2022 12:27:51 +0000 (14:27 +0200)
* lisp/image/image-dired-util.el
(image-dired-thumb-name): Create file names in a portable manner.
* test/lisp/image/image-dired-util-tests.el
(image-dired-thumb-name/standard)
(image-dired-thumb-name/image-dired)
(image-dired-thumb-name/per-directory): Expand tests.

lisp/image/image-dired-util.el
test/lisp/image/image-dired-util-tests.el

index f8e81d2e8d70bb384d7c021c078cd161444e68f6..e7d116d90baaed40bf93b26f3411e4f1994b4c78 100644 (file)
@@ -85,19 +85,22 @@ See also `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)))))
-           (format "%s%s%s.thumb.%s"
-                   (file-name-as-directory (expand-file-name (image-dired-dir)))
-                   (file-name-base f)
-                   (if hash (concat "_" hash) "")
-                   (file-name-extension f))))
+                (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)))
-           (format "%s.image-dired/%s.thumb.%s"
-                   (file-name-directory f)
-                   (file-name-base f)
-                   (file-name-extension f))))))
+           (expand-file-name
+            (format "%s.thumb.%s"
+                    (file-name-base f)
+                    (file-name-extension f))
+            (expand-file-name
+             ".image-dired"
+             (file-name-directory f)))))))
 
 (defvar image-dired-thumbnail-buffer "*image-dired*"
   "Image-Dired's thumbnail buffer.")
index 39862fc6faa7927ef2a8d6142a4c381ea2648c63..9fb457dd36e5b22e721c9756b987178e5858957a 100644 (file)
 (ert-deftest image-dired-thumb-name/standard ()
   (let ((image-dired-thumbnail-storage 'standard))
     (should (file-name-absolute-p (image-dired-thumb-name "foo.jpg")))
+    (should (file-name-absolute-p (image-dired-thumb-name "/tmp/foo.jpg")))
+    (should (equal
+             (file-name-directory (image-dired-thumb-name "foo.jpg"))
+             (file-name-directory (image-dired-thumb-name "/tmp/foo.jpg"))))
     (should (string-search (xdg-cache-home)
                            (image-dired-thumb-name "foo.jpg")))
     (should (string-match (rx (in "0-9a-f") ".png")
     (let ((image-dired-dir dir)
           (image-dired-thumbnail-storage 'image-dired))
       (should (file-name-absolute-p (image-dired-thumb-name "foo.jpg")))
+      (should (file-name-absolute-p (image-dired-thumb-name "/tmp/foo.jpg")))
+      (should (equal
+               (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.
                       (image-dired-thumb-name "/some/path/foo.jpg"))
 (ert-deftest image-dired-thumb-name/per-directory ()
   (let ((image-dired-thumbnail-storage 'per-directory))
     (should (file-name-absolute-p (image-dired-thumb-name "foo.jpg")))
+    (should (file-name-absolute-p (image-dired-thumb-name "/tmp/foo.jpg")))
+    (should (equal
+             (file-name-nondirectory (image-dired-thumb-name "foo.jpg"))
+             (file-name-nondirectory (image-dired-thumb-name "/tmp/foo.jpg"))))
+    (should (equal (file-name-split (image-dired-thumb-name "/tmp/foo.jpg"))
+                   '("" "tmp" ".image-dired" "foo.thumb.jpg")))
     (should (equal (file-name-nondirectory
                     (image-dired-thumb-name "foo.jpg"))
                    "foo.thumb.jpg"))))