about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorFichteFoll <fichtefoll2@googlemail.com>2019-05-22 22:02:01 +0200
committerFichteFoll <fichtefoll2@googlemail.com>2019-05-24 15:28:50 +0200
commita955719f15037eaabb20cd1c8af8bc8d40cadd33 (patch)
treea477cfd3ea05b5846ff56146e10d2afbf0c60ea7
parent6315c2f9f4f9f23770d7f1cd2d8d02cacb2a2729 (diff)
downloadranger-a955719f15037eaabb20cd1c8af8bc8d40cadd33.tar.gz
Open image displaying subprocesses in safe workdir
Otherwise, the current working directory of ranger would be used and
could block operations like unmounting, because the handles would be
kept alive by the previewer even when the directory isn't in use by
ranger anymore.

Fixes #1565.
-rw-r--r--ranger/ext/img_display.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/ranger/ext/img_display.py b/ranger/ext/img_display.py
index 7c9f35a7..2cce5c7a 100644
--- a/ranger/ext/img_display.py
+++ b/ranger/ext/img_display.py
@@ -75,6 +75,8 @@ class ImgDisplayUnsupportedException(Exception):
 class ImageDisplayer(object):
     """Image display provider functions for drawing images in the terminal"""
 
+    working_dir = os.environ.get('XDG_RUNTIME_DIR', os.path.expanduser("~") or None)
+
     def draw(self, path, start_x, start_y, width, height):
         """Draw an image at the given coordinates."""
         pass
@@ -106,7 +108,7 @@ class W3MImageDisplayer(ImageDisplayer, FileManagerAware):
         """start w3mimgdisplay"""
         self.binary_path = None
         self.binary_path = self._find_w3mimgdisplay_executable()  # may crash
-        self.process = Popen([self.binary_path] + W3MIMGDISPLAY_OPTIONS,
+        self.process = Popen([self.binary_path] + W3MIMGDISPLAY_OPTIONS, cwd=self.working_dir,
                              stdin=PIPE, stdout=PIPE, universal_newlines=True)
         self.is_initialized = True
 
@@ -696,7 +698,7 @@ class UeberzugImageDisplayer(ImageDisplayer):
                 and not self.process.stdin.closed):
             return
 
-        self.process = Popen(['ueberzug', 'layer', '--silent'],
+        self.process = Popen(['ueberzug', 'layer', '--silent'], cwd=self.working_dir,
                              stdin=PIPE, universal_newlines=True)
         self.is_initialized = True