Describe the bug
trestle.common.trash.recover() fails to restore directories whose names contain a dot, such as policy.v1.
The function decides whether the destination is a file or directory by checking Path.suffix. Because dotted directory names have a non-empty suffix, recover() incorrectly calls recover_file() instead of recover_dir(). That causes recovery to fail even though the trashed directory exists and can be restored successfully through recover_dir().
To Reproduce
Steps to reproduce the behavior:
- Create a trestle workspace with a
.trestle directory.
- Create a directory with a dot in its name, for example
policy.v1.
- Add a file inside it, such as
readme.md.
- Trash that directory using
trash.store(path_to_directory, True).
- Attempt to restore it using
trash.recover(path_to_directory).
- See recovery fail with an
AssertionError saying the path could not be found in trash.
Expected behavior
trash.recover() should correctly recognize dotted directory names as directories and restore them successfully, just as recover_dir() does.
Screenshots / Logs.
Verified behavior from reproduction:
original exists before store: True True
after store: False False
trash dir path: /home/jay/compliance-trestle/.tmp_trash_verify/.trestle/_trash/policy.v1__bk
trash dir exists: True
trash file path used by recover(): /home/jay/compliance-trestle/.tmp_trash_verify/.trestle/_trash/policy.v1.bk
trash file path exists: False
EXCEPTION_TYPE: AssertionError
EXCEPTION_MSG: Specified path "/home/jay/compliance-trestle/.tmp_trash_verify/policy.v1" could not be found in trash
after recover attempt: False False
Control verification:
stored trash dir exists: True
after recover_dir: True True
This confirms the trash data is valid and the bug is specifically in recover() dispatching to the wrong recovery function.
Environment
- OS: Linux
- Python version: 3.10
- Installed packages:
- project local environment using repo
venv
compliance-trestle dependencies already available there
Describe the bug
trestle.common.trash.recover()fails to restore directories whose names contain a dot, such aspolicy.v1.The function decides whether the destination is a file or directory by checking
Path.suffix. Because dotted directory names have a non-empty suffix,recover()incorrectly callsrecover_file()instead ofrecover_dir(). That causes recovery to fail even though the trashed directory exists and can be restored successfully throughrecover_dir().To Reproduce
Steps to reproduce the behavior:
.trestledirectory.policy.v1.readme.md.trash.store(path_to_directory, True).trash.recover(path_to_directory).AssertionErrorsaying the path could not be found in trash.Expected behavior
trash.recover()should correctly recognize dotted directory names as directories and restore them successfully, just asrecover_dir()does.Screenshots / Logs.
Verified behavior from reproduction:
Control verification:
This confirms the trash data is valid and the bug is specifically in
recover()dispatching to the wrong recovery function.Environment
venvcompliance-trestledependencies already available there