From 95cfbd4cc4bf1f7bde2327b75dded2a727dc3f80 Mon Sep 17 00:00:00 2001 From: TheHubUser4860938 <300190556+TheHubUser4860938@users.noreply.github.com> Date: Tue, 20 Oct 2026 23:59:50 +0200 Subject: [PATCH] Fix #3501: in_trash splits backslashes, so a Windows Recycle Bin path is found on Linux too --- strata_control/discovery.py | 2 +- tests/terminal/test_issues_022.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/strata_control/discovery.py b/strata_control/discovery.py index 94b41583..93ac134c 100644 --- a/strata_control/discovery.py +++ b/strata_control/discovery.py @@ -100,7 +100,7 @@ def in_trash(path: str | os.PathLike) -> bool: """#3410: True when ``path`` is inside a Trash / Recycle Bin folder (a Strata folder that was deleted with the file manager is still a folder there, and was remembered as an install): ~/.local/share/Trash/files/.., /.Trash-1000/.., ~/.Trash/.., $RECYCLE.BIN\\..""" - parts = [x.lower() for x in Path(path).parts] + parts = [x.lower() for p in Path(path).parts for x in str(p).split("\\")] # a Windows-shaped path read on Linux has no separators for Path for i, x in enumerate(parts): if x in (".trash", "$recycle.bin", "recycler", "$recycle.bin.old") or x.startswith(".trash-"): return True diff --git a/tests/terminal/test_issues_022.py b/tests/terminal/test_issues_022.py index b1876bc5..79c4b9b1 100644 --- a/tests/terminal/test_issues_022.py +++ b/tests/terminal/test_issues_022.py @@ -405,5 +405,19 @@ class Issue3488IntegrityRetry(unittest.TestCase): self.assertEqual(ec._hash_settled(path, "good"), "bad") # still wrong after the retry: refuse + +class Issue3501TrashOnPosix(unittest.TestCase): + """A Windows Recycle Bin path read on Linux: Path does not split backslashes there.""" + + def test_windows_path_on_a_posix_path_class(self): + from pathlib import PurePosixPath + from unittest import mock + from strata_control import discovery + with mock.patch.object(discovery, "Path", PurePosixPath): + self.assertTrue(discovery.in_trash(r"C:\$Recycle.Bin\S-1-5-21\$R123\Strata")) + self.assertTrue(discovery.in_trash("/mnt/d/$RECYCLE.BIN/S-1/Strata")) + self.assertFalse(discovery.in_trash(r"C:\Users\a\Strata")) + + if __name__ == "__main__": unittest.main()