From e435581d999873129eda5b32a8bc5cdaf43eaa6c Mon Sep 17 00:00:00 2001 From: blissful Date: Wed, 25 Oct 2023 20:03:20 -0400 Subject: [PATCH] fix bug with opening playlist cover.jpg --- rose/virtualfs.py | 14 +++++++------- rose/virtualfs_test.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rose/virtualfs.py b/rose/virtualfs.py index 196003c..46479e7 100644 --- a/rose/virtualfs.py +++ b/rose/virtualfs.py @@ -29,7 +29,6 @@ list_labels, list_playlists, list_releases, - playlist_exists, release_exists, track_exists, ) @@ -417,8 +416,10 @@ def open(self, path: str, flags: int) -> int: return os.open(str(track.source_path), flags) raise fuse.FuseOSError(err) if p.playlist and p.file: - if not playlist_exists(self.config, p.playlist): - raise fuse.FuseOSError(errno.ENOENT) + try: + playlist, tracks = get_playlist(self.config, p.playlist) # type: ignore + except TypeError as e: + raise fuse.FuseOSError(errno.ENOENT) from e # If we are trying to create a file in the playlist, enter the "add file to playlist" # operation sequence. See the __init__ for more details. if flags & os.O_CREAT == os.O_CREAT: @@ -430,13 +431,12 @@ def open(self, path: str, flags: int) -> int: ) return fh # Otherwise, continue on... - if p.file_position and (pdata := get_playlist(self.config, p.playlist)): - playlist, tracks = pdata + if p.file_position: for idx, track in enumerate(tracks): if track.virtual_filename == p.file and idx + 1 == int(p.file_position): return os.open(str(track.source_path), flags) - if playlist.cover_path and f"cover{playlist.cover_path.suffix}" == p.file: - return os.open(playlist.cover_path, flags) + if playlist.cover_path and f"cover{playlist.cover_path.suffix}" == p.file: + return os.open(playlist.cover_path, flags) raise fuse.FuseOSError(err) diff --git a/rose/virtualfs_test.py b/rose/virtualfs_test.py index 7432a9f..f477f25 100644 --- a/rose/virtualfs_test.py +++ b/rose/virtualfs_test.py @@ -104,9 +104,9 @@ def can_read(p: Path) -> bool: assert not (root / "8. Playlists" / "lalala").exists() assert (root / "8. Playlists" / "Lala Lisa" / "1. 01.m4a").is_file() assert (root / "8. Playlists" / "Lala Lisa" / "cover.jpg").is_file() - print(list((root / "8. Playlists" / "Lala Lisa").iterdir())) assert not (root / "8. Playlists" / "Lala Lisa" / "lalala").exists() assert can_read(root / "8. Playlists" / "Lala Lisa" / "1. 01.m4a") + assert can_read(root / "8. Playlists" / "Lala Lisa" / "cover.jpg") @pytest.mark.usefixtures("seeded_cache")