From 017bb36bdff40383b170e8ee5cff00034595a6ce Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Thu, 9 Feb 2023 19:56:37 +0100 Subject: [PATCH] Image-dired thumb name based on content * lisp/image/image-dired-util.el (image-dired-content-sha1): New utility that compute the SHA-1 of a part of the content of a file. (image-dired-thumb-name): Use it. --- lisp/image/image-dired-util.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el index c03f9d2e3d3..58c96f7f20b 100644 --- a/lisp/image/image-dired-util.el +++ b/lisp/image/image-dired-util.el @@ -57,13 +57,19 @@ image-dired-dir (message "Thumbnail directory created: %s" image-dired-dir)) image-dired-dir)) +(defun image-dired-content-sha1 (filename) + "Compute the SHA-1 of a part of FILENAME." + (with-temp-buffer + (let ((file-size (file-attribute-size (file-attributes filename))) + (chunk-size 4096)) + (insert-file-contents filename nil 0 (min chunk-size file-size)) + (sha1 (current-buffer))))) + (defun image-dired-thumb-name (file) "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 `image-dired', make a SHA1-hash of some of the image file. - 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 @@ -85,7 +91,7 @@ image-dired-thumb-name ((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)) + (expand-file-name (format "%s.jpg" (image-dired-content-sha1 file)) (image-dired-dir))) ((eq 'per-directory image-dired-thumbnail-storage) (expand-file-name (format "%s.thumb.jpg" -- 2.39.0