Fixing bug where multiple files could not be deleted.

This commit is contained in:
Roland 2023-09-08 18:21:13 -06:00
parent 95e870d659
commit a0a4e139fa
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
3 changed files with 25 additions and 4 deletions

View file

@ -147,9 +147,12 @@ async def delete(*paths: Union[str, pathlib.Path]):
if not path.is_dir() and not path.is_file():
raise InvalidFile(f'Cannot delete {path} because it is not a file or a directory.')
if len(paths) > 1:
for p1, p2 in itertools.permutations(paths):
if str(p2).startswith(str(p1)):
raise InvalidFile(f'Cannot deleted nested paths')
for p1 in paths:
for p2 in paths:
if p1 == p2:
continue
if str(p2).startswith(str(p1)):
raise InvalidFile(f'Cannot deleted nested paths')
with get_db_session() as session:
# Search for any files that have been tagged.
for path in paths:

View file

@ -53,6 +53,24 @@ async def test_delete(test_session, make_files_structure, test_directory):
await lib.delete('.')
@pytest.mark.asyncio
async def test_delete_multiple(test_session, make_files_structure, test_directory):
"""Multiple files can be deleted at once."""
foo, bar, baz = make_files_structure([
'archives/foo.txt',
'archives/bar.txt',
'archives/baz.txt',
])
assert foo.is_file()
assert bar.is_file()
assert baz.is_file()
await lib.delete('archives/foo.txt', 'archives/bar.txt', 'archives/baz.txt')
assert not foo.is_file()
assert not bar.is_file()
assert not baz.is_file()
@pytest.mark.asyncio
async def test_delete_link(test_session, test_directory):
"""Links can be deleted."""

View file

@ -1 +1 @@
0.11.2-beta
0.11.3-beta