From f568717f7492c57fbf248ac4dd8d16cd22a24443 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 | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el index c03f9d2e3d3..e54879ce033 100644 --- a/lisp/image/image-dired-util.el +++ b/lisp/image/image-dired-util.el @@ -57,13 +57,17 @@ 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 + (insert-file-contents filename nil 0 4096) + (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 +89,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.1