about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorWojciech Siewierski <wojciech.siewierski@onet.pl>2019-03-10 20:57:36 +0100
committerWojciech Siewierski <wojciech.siewierski@onet.pl>2019-03-10 21:04:07 +0100
commite0e0d5770f599ab928c91a53cc5bd805c16cce95 (patch)
tree6b65e0426079679f1e3b15e9add559622360a610
parentf70c6560b6e950168b0b4481e1f20a7df121d60d (diff)
downloadranger-e0e0d5770f599ab928c91a53cc5bd805c16cce95.tar.gz
Temporarily disable open_all_images if there are too many images
In extreme cases, all the images may be too much to handle by the
system ("Argument list too long", errno 7).  In such cases, let's
Do The Right Thing™ and temporarily disable the open_all_images
setting.  Without this option we'll only open the single image.

Fixes #1488.
-rw-r--r--ranger/core/actions.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 8e98432a..6c98e363 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -410,7 +410,7 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
                         raise
                     self.notify('Error in line `%s\':\n  %s' % (line, str(ex)), bad=True)
 
-    def execute_file(self, files, **kw):
+    def execute_file(self, files, **kw):  # pylint: disable=too-many-branches
         """Uses the "rifle" module to open/execute a file
 
         Arguments are the same as for ranger.ext.rifle.Rifle.execute:
@@ -457,8 +457,22 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         self.signal_emit('execute.before', keywords=kw)
         filenames = [f.path for f in files]
         label = kw.get('label', kw.get('app', None))
-        try:
+
+        def execute():
             return self.rifle.execute(filenames, mode, label, flags, None)
+        try:
+            return execute()
+        except OSError as err:
+            # Argument list too long.
+            if err.errno == 7 and self.settings.open_all_images:
+                old_value = self.settings.open_all_images
+                try:
+                    self.settings.open_all_images = False
+                    return execute()
+                finally:
+                    self.settings.open_all_images = old_value
+            else:
+                raise
         finally:
             self.signal_emit('execute.after')