From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#61394: 30.0.50; [PATCH] Image-dired thumb name based on content Date: Sun, 12 Feb 2023 00:06:32 +0100 Message-ID: <87bklzol8n.fsf@ledu-giraud.fr> References: <874jruy7xx.fsf@ledu-giraud.fr> <87ttztk0yw.fsf@tcd.ie> <87v8k9s6j9.fsf@ledu-giraud.fr> <83ilg8jzti.fsf@gnu.org> <87k00oo03r.fsf@ledu-giraud.fr> <838rh4jlsq.fsf@gnu.org> Reply-To: Manuel Giraud Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24126"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: contovob@tcd.ie, 61394@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 12 00:07:15 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pQyxf-00066q-07 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Feb 2023 00:07:15 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pQyxU-0001kJ-DA; Sat, 11 Feb 2023 18:07:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pQyxS-0001k3-LQ for bug-gnu-emacs@gnu.org; Sat, 11 Feb 2023 18:07:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pQyxS-0000u9-Cx for bug-gnu-emacs@gnu.org; Sat, 11 Feb 2023 18:07:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pQyxS-00070H-7w for bug-gnu-emacs@gnu.org; Sat, 11 Feb 2023 18:07:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 11 Feb 2023 23:07:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 61394 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 61394-submit@debbugs.gnu.org id=B61394.167615679726885 (code B ref 61394); Sat, 11 Feb 2023 23:07:02 +0000 Original-Received: (at 61394) by debbugs.gnu.org; 11 Feb 2023 23:06:37 +0000 Original-Received: from localhost ([127.0.0.1]:43514 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pQyx3-0006zY-3x for submit@debbugs.gnu.org; Sat, 11 Feb 2023 18:06:37 -0500 Original-Received: from ledu-giraud.fr ([51.159.28.247]:36560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pQyx0-0006zN-NZ for 61394@debbugs.gnu.org; Sat, 11 Feb 2023 18:06:36 -0500 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=sGGHyHWd 9782RrFU5s8kjQqFsiYeH2pBAqMaAi2bHZg=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=gy6nMxOjxF2XiaRVSb9QLMYas1KEaF xOw1CLQOURPvdECAPlbppn79fhLXIZupyrFi6Od+1bpixh0++Hnc1wCA== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=sGGHyHWd9782RrFU 5s8kjQqFsiYeH2pBAqMaAi2bHZg=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=KL+z2E7XGgKzq8Ip4Df8K/5WtSH3XSouGZOsQG s9t/7n5sk5WujzT1x/HWiLFxRTTA5xhLAdu3GKA+5tdC4VyNnLI1icfn7LQQaLxHaTUG97 Xt6IFIhIQB3iyVM2t1yuXZBRXLA9adLp0dX2Wnbq4BuVlgUxCoxW9xGZRkasEE2lYiSOxP i46UIqphWe1ZXL6swI9GQ0mXHv53r/SSkroBoyI7tYV4vfPR8xrtIG64JVW9P9VhNrkpct Lc9hIajm7hhPLKk1q9dQYBOBwri86ax4B5PymZfnEcblDSVcdUdgn1cqXa2fuEqS7QvVxb +tG2C5G3fkiEhGLTPO6lu+aQ== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id c96d3c4e (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sun, 12 Feb 2023 00:06:33 +0100 (CET) In-Reply-To: <838rh4jlsq.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 11 Feb 2023 16:53:25 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:255352 Archived-At: --=-=-= Content-Type: text/plain So, here is another version of the patch. I'm not quite sure for the docstring of image-dired-thumb-name. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Image-dired-thumb-name-based-on-contents.patch >From 5cf749b1b321c5f1bd80ae4bb3e1dcf2ba5c02e1 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 contents * lisp/image/image-dired-util.el (image-dired-contents-sha1): New utility that compute the SHA-1 of the first 4KiB of the contents of a file. (image-dired-thumb-name): Fix the docstring and use image-dired-contents-sha1. --- lisp/image/image-dired-util.el | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el index c03f9d2e3d3..cde9d0be8d8 100644 --- a/lisp/image/image-dired-util.el +++ b/lisp/image/image-dired-util.el @@ -57,18 +57,31 @@ image-dired-dir (message "Thumbnail directory created: %s" image-dired-dir)) image-dired-dir)) +(defun image-dired-contents-sha1 (filename) + "Compute the SHA-1 of the first 4KiB of FILENAME's contents." + (with-temp-buffer + (insert-file-contents-literally 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 `per-directory' storage, just add a subdirectory. + +- For `image-dired', make a SHA1-hash the contents of the image + FILE with `image-dired-contents-sha1' and append a \".jpg\" + extension. This thumbnail will be stored in the + `image-dired-dir' directory. + +- For `per-directory', append a \".thumb.jpg\" extension to the + FILE's name. This thumbnail will be stored in a + \".image-dired\" subdirectory into the FILE's directory. + - 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'." (let ((file (expand-file-name file))) (cond ((memq image-dired-thumbnail-storage @@ -85,7 +98,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-contents-sha1 file)) (image-dired-dir))) ((eq 'per-directory image-dired-thumbnail-storage) (expand-file-name (format "%s.thumb.jpg" -- 2.39.1 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--