mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 20:36:21 -05:00
Fixing bug where multiple files could not be deleted.
This commit is contained in:
parent
95e870d659
commit
a0a4e139fa
3 changed files with 25 additions and 4 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
0.11.2-beta
|
||||
0.11.3-beta
|
||||
Loading…
Add table
Add a link
Reference in a new issue