[gnome-news] improve handling of cache directory



commit 7236f056e7ce3c9e005c15df66d9e9c2f2d1f617
Author: Igor Gnatenko <ignatenko redhat com>
Date:   Tue Apr 26 16:28:01 2016 +0200

    improve handling of cache directory
    
    Reported-by: Alexander Larsson <alexl redhat com>
    Reference: https://github.com/alexlarsson/gnome-apps-nightly/issues/28
    Signed-off-by: Igor Gnatenko <ignatenko redhat com>

 gnomenews/application.py |    7 +++----
 gnomenews/post.py        |    5 ++---
 2 files changed, 5 insertions(+), 7 deletions(-)
---
diff --git a/gnomenews/application.py b/gnomenews/application.py
index d748cf3..98a94e4 100644
--- a/gnomenews/application.py
+++ b/gnomenews/application.py
@@ -24,7 +24,7 @@ from gnomenews.about import AboutDialog
 import os
 import os.path
 
-CACHE_PATH = "~/.cache/gnome-news"
+CACHE_PATH = GLib.get_user_cache_dir()
 
 
 class Application(Gtk.Application):
@@ -55,9 +55,8 @@ class Application(Gtk.Application):
 
     @log
     def create_cache(self):
-        cache_full_path = os.path.expanduser(CACHE_PATH)
-        if not os.path.isdir(cache_full_path):
-            os.mkdir(cache_full_path)
+        if not os.path.isdir(CACHE_PATH):
+            GLib.mkdir_with_parents(CACHE_PATH, 0755)
 
     @log
     def do_startup(self):
diff --git a/gnomenews/post.py b/gnomenews/post.py
index aea43a5..ce9f8dd 100644
--- a/gnomenews/post.py
+++ b/gnomenews/post.py
@@ -20,13 +20,12 @@ import os.path
 import re
 
 from gnomenews import log
+from gnomenews.application import CACHE_PATH
 import logging
 logger = logging.getLogger(__name__)
 
 THUMBNAIL_WIDTH = 256
 THUMBNAIL_HEIGHT = 256
-# FIXME: Remove duplication with application.py
-CACHE_PATH = "~/.cache/gnome-news"
 
 NAME_REGEX = re.compile("\(([^\)]+)\)")
 
@@ -55,7 +54,7 @@ class Post(GObject.GObject):
 
         # Check cache first
         hashed_url = hashlib.md5(cursor['url'].encode()).hexdigest()
-        self.cached_thumbnail_path = os.path.join(os.path.expanduser(CACHE_PATH), '%s.png' % hashed_url)
+        self.cached_thumbnail_path = os.path.join(CACHE_PATH, '%s.png' % hashed_url)
 
         GLib.idle_add(self.try_to_load_image_from_cache)
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]