Skip to content

Commit

Permalink
replace [NEW] with {NEW} for better sort order in LC_COLLATE=C
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 21, 2023
1 parent efe5cb6 commit d00d1e5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def seeded_cache(config: Config) -> None:
(id , source_path , cover_image_path , datafile_mtime, virtual_dirname, title , release_type, release_year, multidisc, new , formatted_artists)
VALUES ('r1', '{dirpaths[0]}', null , '999' , 'r1' , 'Release 1', 'album' , 2023 , false , false, 'Techno Man;Bass Man')
, ('r2', '{dirpaths[1]}', '{imagepaths[0]}', '999' , 'r2' , 'Release 2', 'album' , 2021 , false , false, 'Violin Woman feat. Conductor Woman')
, ('r3', '{dirpaths[2]}', null , '999' , '[NEW] r3' , 'Release 3', 'album' , 2021 , false , true , '');
, ('r3', '{dirpaths[2]}', null , '999' , '{NEW} r3' , 'Release 3', 'album' , 2021 , false , true , '');
INSERT INTO releases_genres
(release_id, genre , genre_sanitized)
Expand Down
2 changes: 1 addition & 1 deletion rose/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def update_cache_for_releases(
if release.labels:
release_virtual_dirname += " {" + ";".join(release.labels) + "}"
if release.new:
release_virtual_dirname = "[NEW] " + release_virtual_dirname
release_virtual_dirname = "{NEW} " + release_virtual_dirname
release_virtual_dirname = sanitize_filename(release_virtual_dirname)
# And in case of a name collision, add an extra number at the end. Iterate to
# find the first unused number.
Expand Down
2 changes: 1 addition & 1 deletion rose/cache_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def test_list_releases(config: Config) -> None:
id="r3",
source_path=Path(config.music_source_dir / "r3"),
cover_image_path=None,
virtual_dirname="[NEW] r3",
virtual_dirname="{NEW} r3",
title="Release 3",
type="album",
year=2021,
Expand Down
4 changes: 2 additions & 2 deletions rose/releases_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_toggle_release_new(config: Config) -> None:
assert data["new"] is False
with connect(config) as conn:
cursor = conn.execute("SELECT virtual_dirname FROM releases")
assert not cursor.fetchone()["virtual_dirname"].startswith("[NEW] ")
assert not cursor.fetchone()["virtual_dirname"].startswith("{NEW} ")

# Set new.
toggle_release_new(config, release_id)
Expand All @@ -56,7 +56,7 @@ def test_toggle_release_new(config: Config) -> None:
assert data["new"] is True
with connect(config) as conn:
cursor = conn.execute("SELECT virtual_dirname FROM releases")
assert cursor.fetchone()["virtual_dirname"].startswith("[NEW] ")
assert cursor.fetchone()["virtual_dirname"].startswith("{NEW} ")


def test_resolve_release_ids(config: Config) -> None:
Expand Down
6 changes: 3 additions & 3 deletions rose/virtualfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def getattr(self, path: str, fh: int) -> dict[str, Any]:
# Some early guards just in case.
if p.release and p.collage and not collage_has_release(self.config, p.collage, p.release):
raise fuse.FuseOSError(errno.ENOENT)
if p.release and p.view == "New" and not p.release.startswith("[NEW] "):
if p.release and p.view == "New" and not p.release.startswith("{NEW} "):
raise fuse.FuseOSError(errno.ENOENT)

if p.release and p.file:
Expand Down Expand Up @@ -292,10 +292,10 @@ def rename(self, old: str, new: str) -> None:
# 2. Toggle a release's new status.
if (
(op.release and np.release)
and op.release.removeprefix("[NEW] ") == np.release.removeprefix("[NEW] ")
and op.release.removeprefix("{NEW} ") == np.release.removeprefix("{NEW} ")
and (not op.file and not np.file)
):
if op.release.startswith("[NEW] ") != np.release.startswith("[NEW] "):
if op.release.startswith("{NEW} ") != np.release.startswith("{NEW} "):
toggle_release_new(self.config, op.release)
else:
raise fuse.FuseOSError(errno.EACCES)
Expand Down
14 changes: 7 additions & 7 deletions rose/virtualfs_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def can_read(p: Path) -> bool:
assert can_read(root / "Collages" / "Rose Gold" / "1. r1" / "01.m4a")

assert (root / "New").is_dir()
assert (root / "New" / "[NEW] r3").is_dir()
assert (root / "New" / "{NEW} r3").is_dir()
assert not (root / "New" / "r2").exists()
assert (root / "New" / "[NEW] r3" / "01.m4a").is_file()
assert not (root / "New" / "[NEW] r3" / "lalala").exists()
assert (root / "New" / "{NEW} r3" / "01.m4a").is_file()
assert not (root / "New" / "{NEW} r3" / "lalala").exists()


@pytest.mark.usefixtures("seeded_cache")
Expand Down Expand Up @@ -137,12 +137,12 @@ def test_virtual_filesystem_toggle_new(config: Config, source_dir: Path) -> None
dirname = "NewJeans - 1990. I Love NewJeans [K-Pop;R&B] {A Cool Label}"
root = config.fuse_mount_dir
with startfs(config):
(root / "Releases" / dirname).rename(root / "Releases" / f"[NEW] {dirname}")
assert (root / "Releases" / f"[NEW] {dirname}").is_dir()
(root / "Releases" / dirname).rename(root / "Releases" / f"{NEW} {dirname}")
assert (root / "Releases" / f"{NEW} {dirname}").is_dir()
assert not (root / "Releases" / dirname).exists()
(root / "Releases" / f"[NEW] {dirname}").rename(root / "Releases" / dirname)
(root / "Releases" / f"{NEW} {dirname}").rename(root / "Releases" / dirname)
assert (root / "Releases" / dirname).is_dir()
assert not (root / "Releases" / f"[NEW] {dirname}").exists()
assert not (root / "Releases" / f"{NEW} {dirname}").exists()
with pytest.raises(OSError): # noqa: PT011
(root / "Releases" / dirname).rename(root / "Releases" / "lalala")

Expand Down

0 comments on commit d00d1e5

Please sign in to comment.