Merge lp:~jamestait/gwibber/fix-845374 into lp:gwibber

Proposed by James Tait
Status: Merged
Merged at revision: 1313
Proposed branch: lp:~jamestait/gwibber/fix-845374
Merge into: lp:gwibber
Diff against target: 112 lines (+14/-7)
7 files modified
gwibber/microblog/util/resources.py (+2/-1)
libgwibber-gtk/stream-view-tile.vala (+1/-1)
libgwibber/service.vala (+1/-1)
libgwibber/utils.vala (+1/-1)
tests/Makefile.am (+2/-1)
tests/python/utils/__init__.py (+2/-1)
tests/vala/test-utils.vala (+5/-1)
To merge this branch: bzr merge lp:~jamestait/gwibber/fix-845374
Reviewer Review Type Date Requested Status
Ken VanDine Approve
Review via email: mp+97120@code.launchpad.net

Description of the change

Use the SHA1 hash of the avatar URL instead of simply stripping the slashes, to avoid the resulting filename being too long to be created on ecryptfs volumes. Fixes #845374.

To post a comment you must log in.
Revision history for this message
Ken VanDine (ken-vandine) wrote :

Looks great, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'gwibber/microblog/util/resources.py'
2--- gwibber/microblog/util/resources.py 2012-02-13 20:39:02 +0000
3+++ gwibber/microblog/util/resources.py 2012-03-12 23:57:17 +0000
4@@ -5,6 +5,7 @@
5 """
6
7 import os, sys
8+from hashlib import sha1
9 from os import makedirs, remove, environ
10 from os.path import join, isdir, realpath, exists
11 import Image
12@@ -86,7 +87,7 @@
13 avatar_cache_dir = realpath(join(CACHE_BASE_DIR, "gwibber", "avatars"))
14 if not isdir(avatar_cache_dir):
15 makedirs(avatar_cache_dir)
16- avatar_cache_image = join(avatar_cache_dir, url.replace("/",""))
17+ avatar_cache_image = join(avatar_cache_dir, sha1(url).hexdigest())
18
19 if not exists(avatar_cache_image) or len(open(avatar_cache_image, "r").read()) < 1:
20 logger.debug("Downloading avatar %s", url)
21
22=== modified file 'libgwibber-gtk/stream-view-tile.vala'
23--- libgwibber-gtk/stream-view-tile.vala 2012-03-09 19:31:03 +0000
24+++ libgwibber-gtk/stream-view-tile.vala 2012-03-12 23:57:17 +0000
25@@ -916,7 +916,7 @@
26 b.add (avatar);
27 avatar.show ();
28
29- var cimage = Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace("/",""));
30+ var cimage = Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url));
31 t = "png";
32 if (cimage.has_suffix ("JPG") || cimage.has_suffix ("jpeg") || cimage.has_suffix ("jpg"))
33 t = "jpeg";
34
35=== modified file 'libgwibber/service.vala'
36--- libgwibber/service.vala 2012-02-23 08:59:27 +0000
37+++ libgwibber/service.vala 2012-03-12 23:57:17 +0000
38@@ -467,7 +467,7 @@
39 */
40 public string? avatar_path(string url) throws GLib.Error
41 {
42- string _avatar_cache_image = Path.build_path(Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace("/",""));
43+ string _avatar_cache_image = Path.build_path(Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url));
44 var file = File.new_for_path (_avatar_cache_image);
45 if (file.query_exists ())
46 return _avatar_cache_image;
47
48=== modified file 'libgwibber/utils.vala'
49--- libgwibber/utils.vala 2012-02-23 08:58:10 +0000
50+++ libgwibber/utils.vala 2012-03-12 23:57:17 +0000
51@@ -92,7 +92,7 @@
52
53 public string? avatar_path(string url)
54 {
55- string _avatar_cache_image = Path.build_path(Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace("/",""));
56+ string _avatar_cache_image = Path.build_path(Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url));
57 var file = File.new_for_path (_avatar_cache_image);
58 if (file.query_exists ())
59 return _avatar_cache_image;
60
61=== modified file 'tests/Makefile.am'
62--- tests/Makefile.am 2012-02-15 08:11:57 +0000
63+++ tests/Makefile.am 2012-03-12 23:57:17 +0000
64@@ -23,7 +23,8 @@
65 EXTRA_DIST = \
66 service-start.in \
67 create-account.in \
68- $(top_srcdir)/tests/data/gwibber/avatars/http*test.comavatar \
69+ $(top_srcdir)/tests/data/gwibber/avatars/0ce3002170fed9a8b1fce046d62f9110c926c449 \
70+ $(top_srcdir)/tests/data/gwibber/avatars/8d78e9d550c70f3a73a5aefeda69322aef31de4f \
71 $(top_srcdir)/tests/data/resources/gwibber.stream_model \
72 $(top_srcdir)/tests/plugins/test/__init__.py
73
74
75=== renamed file 'tests/data/gwibber/avatars/http:test.comavatar' => 'tests/data/gwibber/avatars/0ce3002170fed9a8b1fce046d62f9110c926c449'
76=== added file 'tests/data/gwibber/avatars/8d78e9d550c70f3a73a5aefeda69322aef31de4f'
77=== modified file 'tests/python/utils/__init__.py'
78--- tests/python/utils/__init__.py 2012-01-05 17:10:30 +0000
79+++ tests/python/utils/__init__.py 2012-03-12 23:57:17 +0000
80@@ -1,5 +1,6 @@
81 import os, unittest, gettext, mx.DateTime
82 from gi.repository import Gwibber
83+from hashlib import sha1
84
85 class TimeStringTestCase (unittest.TestCase):
86 def setUp (self):
87@@ -46,7 +47,7 @@
88 def test_avatar_path (self):
89 url = "http://test.com/avatar"
90 avatar_path = self.utils.avatar_path (url)
91- self.assertEqual (avatar_path, os.path.join (os.environ["XDG_CACHE_HOME"], "gwibber", "avatars", url.replace ("/","")))
92+ self.assertEqual (avatar_path, os.path.join (os.environ["XDG_CACHE_HOME"], "gwibber", "avatars", sha1(url).hexdigest()))
93
94 test_cases = (TimeStringTestCase, AvatarPathTestCase)
95
96
97=== modified file 'tests/vala/test-utils.vala'
98--- tests/vala/test-utils.vala 2011-12-08 02:11:00 +0000
99+++ tests/vala/test-utils.vala 2012-03-12 23:57:17 +0000
100@@ -98,7 +98,11 @@
101 var utils = new Gwibber.Utils ();
102 string url = "http://test.com/avatar";
103 string avatar_path = utils.avatar_path (url);
104- assert (avatar_path == Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace ("/","")));
105+ assert (avatar_path == Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url)));
106+ url = "http://test.com/this_is_a_very_long_avatar_url_that_should_cause_test_failures_as_per_bug_845374_which_is_scheduled_to_be_fixed_in_a_later_release_but_hopefully_will_be_patched_before_then";
107+ stdout.printf(GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url, url.length));
108+ avatar_path = utils.avatar_path (url);
109+ assert (avatar_path == Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url)));
110 }
111 }
112 }

Subscribers

People subscribed via source and target branches