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
This commit is contained in:
Bryan Schumaker 2011-06-18 09:28:53 -04:00
parent 6773d9837e
commit e6849dc5cd
1 changed files with 6 additions and 1 deletions

View File

@ -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