Skip to content

Commit

Permalink
fix bug where dotted dirs are renamed incorrectly
Browse files Browse the repository at this point in the history
  • Loading branch information
azuline committed Oct 10, 2023
1 parent 80934d9 commit f81c6bd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
17 changes: 13 additions & 4 deletions rose/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import click

from rose.cache.database import migrate_database
from rose.cache.update import update_cache_for_all_releases
from rose.foundation.conf import Config


Expand All @@ -29,14 +30,22 @@ def cli(clickctx: click.Context, verbose: bool) -> None:


@cli.group()
@click.pass_obj
def cache(_: Context) -> None:
def cache() -> None:
"""Manage the cached metadata."""


@cache.command()
def reset() -> None:
"""Reset the cache and empty the database."""
@click.pass_obj
def refresh(c: Context) -> None:
"""Refresh the cached data from disk."""
update_cache_for_all_releases(c.config)


@cache.command()
@click.pass_obj
def clear(c: Context) -> None:
"""Clear the cache; empty the database."""
c.config.cache_database_path.unlink()


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion rose/cache/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,8 @@ def _parse_uuid_from_path(path: Path) -> str | None:


def _rename_with_uuid(src: Path, uuid: str) -> Path:
return src.rename(src.with_stem(src.stem + f" {{id={uuid}}}"))
if src.is_dir():
dst = src.with_name(src.name + f" {{id={uuid}}}")
else:
dst = src.with_stem(src.stem + f" {{id={uuid}}}")
return src.rename(dst)
10 changes: 10 additions & 0 deletions rose/cache/update_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,13 @@ def test_update_cache_for_all_releases(config: Config) -> None:
assert cursor.fetchone()[0] == 2
cursor = conn.execute("SELECT COUNT(*) FROM tracks")
assert cursor.fetchone()[0] == 4


def test_update_cache_with_dotted_dirname(config: Config) -> None:
# Regression test: If we use with_stem on a directory with a dot, then the directory will be
# renamed to like Put.ID.After.The {id=abc}.Dot" which we don't want.
release_dir = config.music_source_dir / "Put.ID.After.The.Dot"
shutil.copytree(TEST_RELEASE_1, release_dir)
updated_release_dir = update_cache_for_release(config, release_dir)
m = ID_REGEX.search(updated_release_dir.name)
assert m is not None

0 comments on commit f81c6bd

Please sign in to comment.