From 413a47eab5d79d03f6d4bd76ff276e3ad0777413 Mon Sep 17 00:00:00 2001 From: Saul Pwanson Date: Wed, 18 Oct 2023 21:50:37 -0700 Subject: [PATCH] [shell] use rmtree on directory unless safety_first #1965 NOTE: This makes the file manager a lot more powerful, and dangerous! Every deleted directory will be deleted recursively when committed. If this is objectionable, set options.safety_first=True. --- visidata/modify.py | 7 +++++-- visidata/shell.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/visidata/modify.py b/visidata/modify.py index d1024b5ce..cf77b2730 100644 --- a/visidata/modify.py +++ b/visidata/modify.py @@ -139,8 +139,11 @@ def deleteBy(sheet, func, commit=False, undo=True): if r is newCursorRow: sheet.cursorRowIndex = len(sheet.rows)-1 else: - sheet.commitDeleteRow(r) - ndeleted += 1 + try: + sheet.commitDeleteRow(r) + ndeleted += 1 + except Exception as e: + vd.exceptionCaught(e) if undo: vd.addUndo(setattr, sheet, 'rows', oldrows) diff --git a/visidata/shell.py b/visidata/shell.py index 0f09b0328..13885b240 100644 --- a/visidata/shell.py +++ b/visidata/shell.py @@ -165,7 +165,10 @@ def renameFile(self, row, val): def removeFile(self, path): if path.is_dir(): - os.rmdir(path) + if self.options.safety_first: + os.rmdir(path) + else: + shutil.rmtree(path) #1965 else: path.unlink()