1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Make image-dired-thumb-name more portable

* 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.
This commit is contained in:
Stefan Kangas 2022-09-25 14:22:06 +02:00
parent 971566e88a
commit a256f49f08
2 changed files with 28 additions and 11 deletions

View 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.")

View file

@ -28,6 +28,10 @@
(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")
@ -39,6 +43,10 @@
(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"))
@ -47,6 +55,12 @@
(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"))))