about summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
author5hir0kur0 <12101162+5hir0kur0@users.noreply.github.com>2020-03-07 20:21:13 +0100
committer5hir0kur0 <12101162+5hir0kur0@users.noreply.github.com>2020-03-07 20:35:17 +0100
commit461d423b5a509e9939d2cc044bf954c864e8ce14 (patch)
treee927da6ea8b3a327740ca3db7c63808df644e412 /ranger
parentefa32996173ee50cb2dbf4eb3d0cc2af998d6f3a (diff)
downloadranger-461d423b5a509e9939d2cc044bf954c864e8ce14.tar.gz
trash: Fix crash on OSError
The trash command used to crash ranger when passing so may arguments
that the argument length limit of the OS is reached.  See the discussion
in pull request #1871 for steps to reproduce.

Now it displays an error message instead of crashing.
(It does not move the files to trash though.)
Diffstat (limited to 'ranger')
-rwxr-xr-xranger/config/commands.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index ecbb2fe1..499bf3ef 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -753,7 +753,7 @@ class trash(Command):
             )
         else:
             # no need for a confirmation, just delete
-            self.fm.execute_file(files, label='trash')
+            self._trash_files_catch_arg_list_error(files)
 
     @staticmethod
     def group_paths_by_dirname(paths):
@@ -797,7 +797,21 @@ class trash(Command):
 
     def _question_callback(self, files, answer):
         if answer == 'y' or answer == 'Y':
+            self._trash_files_catch_arg_list_error(files)
+
+    def _trash_files_catch_arg_list_error(self, files):
+        """
+        Executes the fm.execute_file method but catches the OSError ("Argument list too long")
+        that occurs when moving too many files to trash (and would otherwise crash ranger).
+        """
+        try:
             self.fm.execute_file(files, label='trash')
+        except OSError as err:
+            if err.errno == 7:
+                self.fm.notify("Error: Command too long (try passing less files at once)",
+                               bad=True)
+            else:
+                raise
 
 
 class jump_non(Command):