From: Stefan Kangas Date: Sun, 24 Oct 2021 21:25:07 +0000 (+0200) Subject: Use SHA1 when creating thumbnail file name X-Git-Tag: emacs-29.0.90~3671^2~430 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=608e694a30469392540043ce3ef627832b491f8c;p=emacs.git Use SHA1 when creating thumbnail file name * 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. --- diff --git a/lisp/image-dired.el b/lisp/image-dired.el index 0a4db7a0e55..bca2dd117f4 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el @@ -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)))