Skip to content

Commit

Permalink
[shell] use rmtree on directory unless safety_first #1965
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
saulpw committed Oct 19, 2023
1 parent cd3bdeb commit 413a47e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions visidata/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion visidata/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 413a47e

Please sign in to comment.