Fix #3501: in_trash splits backslashes, so a Windows Recycle Bin path is found on Linux too
This commit is contained in:
1 parent
c8b1436022
commit
95cfbd4cc4
2 files changed
+15
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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()
|
||||
Reference in new issue
Block a user