I started noticing some time ago in Xfce4 that when I sent some file to the Trash, tumbler (the Xfce4 thumbnailer) would cause very high I/O load for quite some time. Upon investigating the issue, I found that it was scanning the ~/.thumbnails directory, which was very large in size.

So I decided to write a cron script that will periodically clean the ~/.thumbnails directory, but there is a certain directory of large video files that tumbler takes a bit of time, and sometimes even fails, to create thumbnails for.

The idea is removing all thumbnails, except the ones for these videos. But in order to keep these thumbnails, I have to find what their names are. The problem is that thumbnails are stored named with a md5sum of the URI, plus the PNG extension.

Upon looking at the tumbler source, I found the name for the thumbnail is generated in the following line:

md5_hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);

The documentation for g-compute-checksum-for-string says:

g_compute_checksum_for_string(GChecksumType checksum_type,
                              const gchar *str,
                              gssize length);

checksum_type: a GChecksumType 
str:           the string to compute the checksum of
length:        the length of the string, or -1 if the string is null-terminated.

To put it short, the thumbnail for a file named /home/teresaejunior/File 01.png will be stored in the .thumbnails/ directory as a8502be3273541e618b840204479a7f9.png

According to the ThumbnailerSpec, URI is file://filename. I did some research on the "null character", and thought \0 would do the trick. In order to achieve the result a8502be3273541e618b840204479a7f9, I believed the following should work:

printf "file:///home/teresaejunior/File 01.png\0" | md5sum

but that returns f507285c45d293fa66bc0b813d17b6e6 instead.

Can someone give me some advice? I believe my printf line is flawed. What is my command doing different from g_compute_checksum_for_string?

share|improve this question
    
No, that string returns that hash here. >>> m = hashlib.md5('file:///home/teresaejunior/File 01.png\0') >>> m.hexdigest() 'f507285c45d293fa66bc0b813d17b6e6' – Ignacio Vazquez-Abrams Sep 19 '13 at 1:44
    
@IgnacioVazquez-Abrams The thumbnail for this file is stored as a8502be3273541e618b840204479a7f9, although it was generated by the function I mentioned. Please, click on the link for the tumbler source for details. – Teresa e Junior Sep 19 '13 at 1:47
    
Right, but the NUL in your command is not the problem. – Ignacio Vazquez-Abrams Sep 19 '13 at 1:47
1  
Can't answer, but you can confirm that you are indeed printing the null string by passing through od: printf "file:///home/teresaejunior/File 01.png\0" | od -c. – terdon Sep 19 '13 at 3:23
up vote 4 down vote accepted

The NUL character is not included when the MD5 is calculated. Rather, it's the space character that's causing your problem. The filename is URL-encoded:

$ printf '%s' 'file:///home/teresaejunior/File%2001.png' | md5sum
a8502be3273541e618b840204479a7f9  -

Here's one way to do the conversion with Perl:

$ perl -MURI::file -MDigest::MD5=md5_hex \
  -e 'printf "%s.png\n", md5_hex(URI::file->new(shift))' \
  '/home/teresaejunior/File 01.png'
a8502be3273541e618b840204479a7f9.png
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.