diff options
author | 5hir0kur0 <12101162+5hir0kur0@users.noreply.github.com> | 2020-03-05 10:04:59 +0100 |
---|---|---|
committer | 5hir0kur0 <12101162+5hir0kur0@users.noreply.github.com> | 2020-03-05 10:04:59 +0100 |
commit | f65e6f08bcf63b7d915d2a2e98d1f6f891cd30de (patch) | |
tree | d9fb460f96c627eb0cba89d899183e638fc94586 /ranger | |
parent | 081e73152a9391211770fab56676d7d974413ae6 (diff) | |
download | ranger-f65e6f08bcf63b7d915d2a2e98d1f6f891cd30de.tar.gz |
Fix crashes when deleting to trash
The execute() method of the trash command (in ranger/config/commands.py) used to pass a list of file paths (as strings) to fm.execute_file(). The documentation of the execute_file() method states that the 'files' parameter must not be strings: [...] files: a list of file objects (not strings!) [...] So I changed 'files' to be a list of File objects and that seems to fix the issue. Fixes #1798
Diffstat (limited to 'ranger')
-rwxr-xr-x | ranger/config/commands.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py index 5defa677..a2d13542 100755 --- a/ranger/config/commands.py +++ b/ranger/config/commands.py @@ -722,13 +722,15 @@ class trash(Command): def execute(self): import shlex from functools import partial + from ranger.container.file import File def is_directory_with_files(path): return os.path.isdir(path) and not os.path.islink(path) and len(os.listdir(path)) > 0 if self.rest(1): - files = shlex.split(self.rest(1)) - many_files = (len(files) > 1 or is_directory_with_files(files[0])) + file_names = shlex.split(self.rest(1)) + files = [File(name) for name in file_names] + many_files = (len(files) > 1 or is_directory_with_files(files[0].path)) else: cwd = self.fm.thisdir tfile = self.fm.thisfile @@ -736,14 +738,15 @@ class trash(Command): self.fm.notify("Error: no file selected for deletion!", bad=True) return + files = self.fm.thistab.get_selection() # relative_path used for a user-friendly output in the confirmation. - files = [f.relative_path for f in self.fm.thistab.get_selection()] + file_names = [f.relative_path for f in files] many_files = (cwd.marked_items or is_directory_with_files(tfile.path)) confirm = self.fm.settings.confirm_on_delete if confirm != 'never' and (confirm != 'multiple' or many_files): self.fm.ui.console.ask( - "Confirm deletion of: %s (y/N)" % ', '.join(files), + "Confirm deletion of: %s (y/N)" % ', '.join(file_names), partial(self._question_callback, files), ('n', 'N', 'y', 'Y'), ) |