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
=== modified file 'gwibber/microblog/util/resources.py'
--- gwibber/microblog/util/resources.py 2012-02-13 20:39:02 +0000
+++ gwibber/microblog/util/resources.py 2012-03-12 23:57:17 +0000
@@ -5,6 +5,7 @@
5"""5"""
66
7import os, sys7import os, sys
8from hashlib import sha1
8from os import makedirs, remove, environ9from os import makedirs, remove, environ
9from os.path import join, isdir, realpath, exists10from os.path import join, isdir, realpath, exists
10import Image11import Image
@@ -86,7 +87,7 @@
86 avatar_cache_dir = realpath(join(CACHE_BASE_DIR, "gwibber", "avatars"))87 avatar_cache_dir = realpath(join(CACHE_BASE_DIR, "gwibber", "avatars"))
87 if not isdir(avatar_cache_dir):88 if not isdir(avatar_cache_dir):
88 makedirs(avatar_cache_dir)89 makedirs(avatar_cache_dir)
89 avatar_cache_image = join(avatar_cache_dir, url.replace("/",""))90 avatar_cache_image = join(avatar_cache_dir, sha1(url).hexdigest())
9091
91 if not exists(avatar_cache_image) or len(open(avatar_cache_image, "r").read()) < 1:92 if not exists(avatar_cache_image) or len(open(avatar_cache_image, "r").read()) < 1:
92 logger.debug("Downloading avatar %s", url)93 logger.debug("Downloading avatar %s", url)
9394
=== modified file 'libgwibber-gtk/stream-view-tile.vala'
--- libgwibber-gtk/stream-view-tile.vala 2012-03-09 19:31:03 +0000
+++ libgwibber-gtk/stream-view-tile.vala 2012-03-12 23:57:17 +0000
@@ -916,7 +916,7 @@
916 b.add (avatar);916 b.add (avatar);
917 avatar.show ();917 avatar.show ();
918918
919 var cimage = Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace("/",""));919 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));
920 t = "png";920 t = "png";
921 if (cimage.has_suffix ("JPG") || cimage.has_suffix ("jpeg") || cimage.has_suffix ("jpg"))921 if (cimage.has_suffix ("JPG") || cimage.has_suffix ("jpeg") || cimage.has_suffix ("jpg"))
922 t = "jpeg";922 t = "jpeg";
923923
=== modified file 'libgwibber/service.vala'
--- libgwibber/service.vala 2012-02-23 08:59:27 +0000
+++ libgwibber/service.vala 2012-03-12 23:57:17 +0000
@@ -467,7 +467,7 @@
467 */467 */
468 public string? avatar_path(string url) throws GLib.Error468 public string? avatar_path(string url) throws GLib.Error
469 {469 {
470 string _avatar_cache_image = Path.build_path(Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace("/",""));470 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));
471 var file = File.new_for_path (_avatar_cache_image);471 var file = File.new_for_path (_avatar_cache_image);
472 if (file.query_exists ())472 if (file.query_exists ())
473 return _avatar_cache_image;473 return _avatar_cache_image;
474474
=== modified file 'libgwibber/utils.vala'
--- libgwibber/utils.vala 2012-02-23 08:58:10 +0000
+++ libgwibber/utils.vala 2012-03-12 23:57:17 +0000
@@ -92,7 +92,7 @@
9292
93 public string? avatar_path(string url)93 public string? avatar_path(string url)
94 {94 {
95 string _avatar_cache_image = Path.build_path(Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace("/",""));95 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));
96 var file = File.new_for_path (_avatar_cache_image);96 var file = File.new_for_path (_avatar_cache_image);
97 if (file.query_exists ())97 if (file.query_exists ())
98 return _avatar_cache_image;98 return _avatar_cache_image;
9999
=== modified file 'tests/Makefile.am'
--- tests/Makefile.am 2012-02-15 08:11:57 +0000
+++ tests/Makefile.am 2012-03-12 23:57:17 +0000
@@ -23,7 +23,8 @@
23EXTRA_DIST = \23EXTRA_DIST = \
24 service-start.in \24 service-start.in \
25 create-account.in \25 create-account.in \
26 $(top_srcdir)/tests/data/gwibber/avatars/http*test.comavatar \26 $(top_srcdir)/tests/data/gwibber/avatars/0ce3002170fed9a8b1fce046d62f9110c926c449 \
27 $(top_srcdir)/tests/data/gwibber/avatars/8d78e9d550c70f3a73a5aefeda69322aef31de4f \
27 $(top_srcdir)/tests/data/resources/gwibber.stream_model \28 $(top_srcdir)/tests/data/resources/gwibber.stream_model \
28 $(top_srcdir)/tests/plugins/test/__init__.py 29 $(top_srcdir)/tests/plugins/test/__init__.py
2930
3031
=== renamed file 'tests/data/gwibber/avatars/http:test.comavatar' => 'tests/data/gwibber/avatars/0ce3002170fed9a8b1fce046d62f9110c926c449'
=== added file 'tests/data/gwibber/avatars/8d78e9d550c70f3a73a5aefeda69322aef31de4f'
=== modified file 'tests/python/utils/__init__.py'
--- tests/python/utils/__init__.py 2012-01-05 17:10:30 +0000
+++ tests/python/utils/__init__.py 2012-03-12 23:57:17 +0000
@@ -1,5 +1,6 @@
1import os, unittest, gettext, mx.DateTime1import os, unittest, gettext, mx.DateTime
2from gi.repository import Gwibber2from gi.repository import Gwibber
3from hashlib import sha1
34
4class TimeStringTestCase (unittest.TestCase):5class TimeStringTestCase (unittest.TestCase):
5 def setUp (self):6 def setUp (self):
@@ -46,7 +47,7 @@
46 def test_avatar_path (self):47 def test_avatar_path (self):
47 url = "http://test.com/avatar"48 url = "http://test.com/avatar"
48 avatar_path = self.utils.avatar_path (url)49 avatar_path = self.utils.avatar_path (url)
49 self.assertEqual (avatar_path, os.path.join (os.environ["XDG_CACHE_HOME"], "gwibber", "avatars", url.replace ("/","")))50 self.assertEqual (avatar_path, os.path.join (os.environ["XDG_CACHE_HOME"], "gwibber", "avatars", sha1(url).hexdigest()))
5051
51test_cases = (TimeStringTestCase, AvatarPathTestCase)52test_cases = (TimeStringTestCase, AvatarPathTestCase)
5253
5354
=== modified file 'tests/vala/test-utils.vala'
--- tests/vala/test-utils.vala 2011-12-08 02:11:00 +0000
+++ tests/vala/test-utils.vala 2012-03-12 23:57:17 +0000
@@ -98,7 +98,11 @@
98 var utils = new Gwibber.Utils ();98 var utils = new Gwibber.Utils ();
99 string url = "http://test.com/avatar";99 string url = "http://test.com/avatar";
100 string avatar_path = utils.avatar_path (url);100 string avatar_path = utils.avatar_path (url);
101 assert (avatar_path == Path.build_path (Path.DIR_SEPARATOR_S, Environment.get_user_cache_dir(), "gwibber/avatars", url.replace ("/","")));101 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)));
102 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";
103 stdout.printf(GLib.Checksum.compute_for_string(GLib.ChecksumType.SHA1, url, url.length));
104 avatar_path = utils.avatar_path (url);
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)));
102 }106 }
103 }107 }
104}108}

Subscribers

People subscribed via source and target branches