]> git.eshelyaron.com Git - emacs.git/commitdiff
Use SHA1 when creating thumbnail file name
authorStefan Kangas <stefan@marxist.se>
Sun, 24 Oct 2021 21:25:07 +0000 (23:25 +0200)
committerStefan Kangas <stefan@marxist.se>
Sun, 24 Oct 2021 21:26:25 +0000 (23:26 +0200)
* lisp/image-dired.el (image-dired-thumb-name): Improve docstring.
Use SHA1 for hashing when creating file name.  SHA1 is slightly faster
than MD5, and has a few more bits.

lisp/image-dired.el

index 0a4db7a0e553b65e05fa1a2e9d341bbcaa7e5788..bca2dd117f45f5836755e0ae075dcd72d47f9234 100644 (file)
@@ -599,13 +599,18 @@ Add text properties ORIGINAL-FILE-NAME and ASSOCIATED-DIRED-BUFFER."
            'comment (image-dired-get-comment original-file-name)))))
 
 (defun image-dired-thumb-name (file)
-  "Return thumbnail file name for FILE.
-Depending on the value of `image-dired-thumbnail-storage', the file
-name will vary.  For central thumbnail file storage, make a
-MD5-hash of the image file's directory name and add that to make
-the thumbnail file name unique.  For per-directory storage, just
-add a subdirectory.  For standard storage, produce the file name
-according to the Thumbnail Managing Standard."
+  "Return absolute file name for thumbnail FILE.
+Depending on the value of `image-dired-thumbnail-storage', the
+file name of the thumbnail will vary:
+- For `use-image-dired-dir', make a SHA1-hash of the image file's
+  directory name and add that to make the thumbnail file name
+  unique.
+- For `per-directory' storage, just add a subdirectory.
+- For `standard' storage, produce the file name according to the
+  Thumbnail Managing Standard.  Among other things, an MD5-hash
+  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 '(standard standard-large))
          (let* ((xdg (getenv "XDG_CACHE_HOME"))
                 (dir (if (and xdg (file-name-absolute-p xdg))
@@ -614,20 +619,19 @@ according to the Thumbnail Managing Standard."
                             (standard "thumbnails/normal")
                             (standard-large "thumbnails/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 dir))))
         ((eq 'use-image-dired-dir image-dired-thumbnail-storage)
          (let* ((f (expand-file-name file))
-                (md5-hash
-                 ;; Is MD5 hashes fast enough? The checksum of a
-                 ;; thumbnail file name need not be that
-                 ;; "cryptographically" good so a faster one could
-                 ;; be used here.
-                 (md5 (file-name-as-directory (file-name-directory f)))))
+                (hash
+                 ;; SHA1 is slightly faster than MD5, so let's use it.
+                 ;; (We don't need anything crytographically strong.)
+                 (sha1 (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 md5-hash (concat "_" md5-hash) "")
+                   (if hash (concat "_" hash) "")
                    (file-name-extension f))))
         ((eq 'per-directory image-dired-thumbnail-storage)
          (let ((f (expand-file-name file)))