Skip to content

Commit

Permalink
Merge pull request #994 from emnoor-reef/fix-rm
Browse files Browse the repository at this point in the history
Fix non-recursive rm deleting files in subdirectories
  • Loading branch information
mjurbanski-reef committed Feb 13, 2024
2 parents 1d63f46 + d8c4e96 commit 1aa1b62
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion b2/_internal/console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,11 @@ def run(self) -> None:
self.messages_queue.put(self.END_MARKER)

def _run_removal(self, executor: Executor):
for file_version, _ in self.runner._get_ls_generator(self.args):
for file_version, subdirectory in self.runner._get_ls_generator(self.args):
if subdirectory is not None:
# This file_version is not for listing/deleting.
# It is only here to list the subdirectory, so skip deleting it.
continue
# Obtaining semaphore limits number of elements that we fetch from LS.
self.semaphore.acquire(blocking=True)
# This event is updated before the semaphore is released. This way,
Expand Down
2 changes: 2 additions & 0 deletions changelog.d/+fix-rm-non-recursive.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed a bug where `rm bucketName folderName` command without the `--recursive` flag would
remove a file from every subdirectory inside `folderName`.
3 changes: 3 additions & 0 deletions test/unit/test_console_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,9 @@ def test_rm_no_recursive(self):
expected_stdout = '''
a/test.csv
a/test.tsv
b/b/test.csv
b/b1/test.csv
b/b2/test.tsv
c/test.csv
c/test.tsv
'''
Expand Down

0 comments on commit 1aa1b62

Please sign in to comment.