unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Basil Contovounesios <contovob@tcd.ie>
Cc: 61394@debbugs.gnu.org
Subject: bug#61394: 30.0.50; [PATCH] Image-dired thumb name based on content
Date: Fri, 10 Feb 2023 19:46:02 +0100	[thread overview]
Message-ID: <87v8k9s6j9.fsf@ledu-giraud.fr> (raw)
In-Reply-To: <87ttztk0yw.fsf@tcd.ie> (Basil Contovounesios's message of "Fri,  10 Feb 2023 15:13:27 +0000")

[-- Attachment #1: Type: text/plain, Size: 1047 bytes --]

Basil Contovounesios <contovob@tcd.ie> writes:

> Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of
> text editors" [2023-02-09 20:06 +0100] wrote:
>
>> +(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))
>
> Can't we unconditionally pass END=chunk-size to insert-file-contents,
> even for smaller files?

From fileio.c:4076, it seems that you are right:

--8<---------------cut here---------------start------------->8---
      /* The likely offset where we will stop reading.  We could read
	 more (or less), if the file grows (or shrinks) as we read it.  */
      off_t likely_end = min (end_offset, st.st_size);
--8<---------------cut here---------------end--------------->8---

So here is an update version of this patch.  I've tested it on small 400
bytes icons and it works also.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Image-dired-thumb-name-based-on-content.patch --]
[-- Type: text/x-patch, Size: 2130 bytes --]

From f568717f7492c57fbf248ac4dd8d16cd22a24443 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
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


[-- Attachment #3: Type: text/plain, Size: 27 bytes --]


Thanks,
-- 
Manuel Giraud

  reply	other threads:[~2023-02-10 18:46 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-09 19:06 bug#61394: 30.0.50; [PATCH] Image-dired thumb name based on content Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-10 15:13 ` Basil Contovounesios via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-10 18:46   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-02-11  9:50     ` Eli Zaretskii
2023-02-11 12:30       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-11 14:53         ` Eli Zaretskii
2023-02-11 22:33           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-11 23:06           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-12  3:02             ` Stefan Kangas
2023-02-12 21:53               ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-15 14:19                 ` Stefan Kangas
2023-02-15 15:35                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-19 14:06                     ` Stefan Kangas
2023-02-19 14:43                       ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-19 16:19                         ` Stefan Kangas
2023-02-20  9:20                           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-02-25 18:45                           ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-26 19:18                             ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-27  7:04                               ` Eli Zaretskii
2023-07-27 13:52                                 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-27 14:16                                   ` Eli Zaretskii
2023-07-27 21:30                                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-28  6:55                                       ` Eli Zaretskii
2023-07-28  9:33                                         ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-28 12:20                                           ` Eli Zaretskii
2023-07-28 16:00                                             ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-28 18:44                                               ` Eli Zaretskii
2023-07-29  9:51                                                 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-29 10:34                                                   ` Eli Zaretskii
2023-07-29 16:50                                                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-03  8:43                                                       ` Eli Zaretskii
2023-07-29 10:47                                                   ` Michael Albinus
2023-07-31 15:53                                                   ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-01 17:05                                                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-02 11:42                                                       ` Eli Zaretskii
2023-08-02 18:00                                                         ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-02 18:16                                                           ` Eli Zaretskii
2023-08-03 11:10                                                             ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-03 11:38                                                               ` Eli Zaretskii
2023-08-03 16:51                                                                 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-03 18:30                                                                   ` Eli Zaretskii
2023-08-04  7:44                                                                     ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-04 10:55                                                                       ` Eli Zaretskii
2023-08-04 13:37                                                                         ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-08-04 14:05                                                                           ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87v8k9s6j9.fsf@ledu-giraud.fr \
    --to=bug-gnu-emacs@gnu.org \
    --cc=61394@debbugs.gnu.org \
    --cc=contovob@tcd.ie \
    --cc=manuel@ledu-giraud.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).