Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/trestle/utils/trash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def test_to_origin_dir_path(tmp_path: pathlib.Path) -> None:
trash.to_origin_dir_path(trash_file_path)


def test_to_origin_dir_path_with_bk_in_name(tmp_path: pathlib.Path) -> None:
"""Test to_origin_dir_path handles directory names containing __bk."""
test_utils.ensure_trestle_config_dir(tmp_path)
bk_dir = tmp_path / 'alpha__bkbeta'
trash_dir_path = trash.to_trash_dir_path(bk_dir)
(tmp_path / trash.TRESTLE_TRASH_DIR).mkdir(exist_ok=True, parents=True)
origin_dir = trash.to_origin_dir_path(trash_dir_path)
assert bk_dir.resolve() == origin_dir.resolve()


def test_to_origin_file_path(tmp_path: pathlib.Path) -> None:
"""Test to origin file path function."""
test_utils.ensure_trestle_config_dir(tmp_path)
Expand Down
11 changes: 7 additions & 4 deletions trestle/common/trash.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def to_origin_dir_path(trash_dir_path: pathlib.Path) -> pathlib.Path:

origin_path_parts: List[str] = []
for item in relative_path.parts:
parts = item.split(TRESTLE_TRASH_DIR_EXT)
origin_path_parts.append(parts[0])
if item.endswith(TRESTLE_TRASH_DIR_EXT):
item = item[:-len(TRESTLE_TRASH_DIR_EXT)]
origin_path_parts.append(item)

origin_relative_path = pathlib.Path('/'.join(origin_path_parts))
origin_path = trestle_root / origin_relative_path
Expand All @@ -121,8 +122,10 @@ def to_origin_file_path(trash_file_path: pathlib.Path) -> pathlib.Path:
raise AssertionError(f'File path "{trash_file_path}" is not a valid trash file path')

origin_dir = to_origin_dir_path(trash_file_path.parent)
file_parts = trash_file_path.name.split(TRESTLE_TRASH_FILE_EXT)
origin_file_path = origin_dir / file_parts[0]
file_name = trash_file_path.name
if file_name.endswith(TRESTLE_TRASH_FILE_EXT):
file_name = file_name[:-len(TRESTLE_TRASH_FILE_EXT)]
origin_file_path = origin_dir / file_name

return origin_file_path

Expand Down
Loading