Skip to content

Commit

Permalink
fix bug with opening playlist cover.jpg
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 26, 2023
1 parent b5605ac commit e435581
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions rose/virtualfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
list_labels,
list_playlists,
list_releases,
playlist_exists,
release_exists,
track_exists,
)
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion rose/virtualfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit e435581

Please sign in to comment.