Fix cache download deletion

This commit is contained in:
Sumner Evans
2019-06-29 21:01:09 -06:00
parent c11d6759b6
commit 83f60f0a89
2 changed files with 19 additions and 8 deletions

View File

@@ -1,4 +1,5 @@
import os
import glob
import threading
import shutil
import json
@@ -170,9 +171,13 @@ class CacheManager(metaclass=Singleton):
return str(abs_path)
def delete_cache(self, relative_path: Union[Path, str]):
"""
:param relative_path: The path to the cached element to delete.
Note that this can be a globed path.
"""
abs_path = self.calculate_abs_path(relative_path)
if abs_path.exists():
abs_path.unlink()
for path in glob.glob(str(abs_path)):
Path(path).unlink()
def get_playlists(
self,
@@ -214,7 +219,8 @@ class CacheManager(metaclass=Singleton):
# Invalidate the cached photo if we are forcing a retrieval
# from the server.
if force:
self.delete_cache(playlist_details.coverArt)
cover_art_filename = f'cover_art/{playlist_details.coverArt}_*'
self.delete_cache(cover_art_filename)
return playlist_details

View File

@@ -274,13 +274,13 @@ class PlaylistsPanel(Gtk.Paned):
def on_playlist_edit_button_click(self, button):
selected = self.playlist_list.get_selected_row()
playlist_id = self.playlist_map[selected.get_index()].id
playlist = self.playlist_map[selected.get_index()]
dialog = EditPlaylistDialog(
self.get_toplevel(),
CacheManager.get_playlist(playlist_id).result())
CacheManager.get_playlist(playlist.id).result())
def on_delete_playlist(e):
CacheManager.delete_playlist(playlist_id)
CacheManager.delete_playlist(playlist.id)
dialog.destroy()
self.update_playlist_list(force=True)
@@ -289,12 +289,17 @@ class PlaylistsPanel(Gtk.Paned):
result = dialog.run()
if result == Gtk.ResponseType.OK:
CacheManager.update_playlist(
playlist_id,
playlist.id,
name=dialog.data['Name'].get_text(),
comment=dialog.data['Comment'].get_text(),
public=dialog.data['Public'].get_active(),
)
self.update_playlist_view(playlist_id, force=True)
cover_art_filename = f'cover_art/{playlist.coverArt}_*'
CacheManager.delete_cache(cover_art_filename)
self.update_playlist_list(force=True)
self.update_playlist_view(playlist.id, force=True)
dialog.destroy()
def on_playlist_list_download_all_button_click(self, button):