diff --git a/wrolpi/files/lib.py b/wrolpi/files/lib.py index 27c3d554..ad78a046 100644 --- a/wrolpi/files/lib.py +++ b/wrolpi/files/lib.py @@ -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: diff --git a/wrolpi/files/test/test_lib.py b/wrolpi/files/test/test_lib.py index 75b42378..6276c1d1 100644 --- a/wrolpi/files/test/test_lib.py +++ b/wrolpi/files/test/test_lib.py @@ -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.""" diff --git a/wrolpi/version.txt b/wrolpi/version.txt index aa17bdbc..4ba6ee8f 100644 --- a/wrolpi/version.txt +++ b/wrolpi/version.txt @@ -1 +1 @@ -0.11.2-beta \ No newline at end of file +0.11.3-beta \ No newline at end of file