From e6849dc5cd13a5bc5d322fd9318460bbbaceb83c Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 18 Jun 2011 09:28:53 -0400 Subject: [PATCH] libsaria: Only delete empty cache files For some reason I was trying to delete files that don't even exist in the cache! This was stupid and caused an error. Now I only delete empty files --- libsaria/storage/cache.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libsaria/storage/cache.py b/libsaria/storage/cache.py index 17a15f61..fa2036de 100644 --- a/libsaria/storage/cache.py +++ b/libsaria/storage/cache.py @@ -17,6 +17,11 @@ def file_exists(cache_path): return False return getsize(cache_path) != 0 +def file_empty(cache_path): + if not isfile(cache_path): + return False + return getsize(cache_path) == 0 + def make_cache_path(artist, album, file): cache_file = "%s%s%s%s" % (artist, sep, album, sep) cache_path = join(CACHE_DIR, cache_file) @@ -28,7 +33,7 @@ def fill_cache(artist, album, title, cache_func, cache_path): f = open(cache_path, 'w') cache_func(artist, album, title, f) f.close() - if not file_exists(cache_path): + if file_empty(cache_path): os.remove(cache_path) return None return cache_path