Skip to content

trash.recover() fails for directory names containing dots #2187

Description

@Jay2006sawant

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:

  1. Create a trestle workspace with a .trestle directory.
  2. Create a directory with a dot in its name, for example policy.v1.
  3. Add a file inside it, such as readme.md.
  4. Trash that directory using trash.store(path_to_directory, True).
  5. Attempt to restore it using trash.recover(path_to_directory).
  6. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions