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:
parent
6773d9837e
commit
e6849dc5cd
|
@ -17,6 +17,11 @@ def file_exists(cache_path):
|
||||||
return False
|
return False
|
||||||
return getsize(cache_path) != 0
|
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):
|
def make_cache_path(artist, album, file):
|
||||||
cache_file = "%s%s%s%s" % (artist, sep, album, sep)
|
cache_file = "%s%s%s%s" % (artist, sep, album, sep)
|
||||||
cache_path = join(CACHE_DIR, cache_file)
|
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')
|
f = open(cache_path, 'w')
|
||||||
cache_func(artist, album, title, f)
|
cache_func(artist, album, title, f)
|
||||||
f.close()
|
f.close()
|
||||||
if not file_exists(cache_path):
|
if file_empty(cache_path):
|
||||||
os.remove(cache_path)
|
os.remove(cache_path)
|
||||||
return None
|
return None
|
||||||
return cache_path
|
return cache_path
|
||||||
|
|
Loading…
Reference in New Issue