Graphics protocol: Only delete temporary image-data files if they are in a known temporary file location

This commit is contained in:
Kovid Goyal
2018-12-11 10:00:43 +05:30
parent 4a8562a85f
commit d20c65ef80
5 changed files with 41 additions and 7 deletions
+17
View File
@@ -432,3 +432,20 @@ def get_editor():
ans = shlex.split(ans)
get_editor.ans = ans
return ans
def is_path_in_temp_dir(path):
if not path:
return False
def abspath(x):
if x:
return os.path.abspath(os.path.realpath(x))
import tempfile
path = abspath(path)
candidates = frozenset(map(abspath, ('/tmp', '/dev/shm', os.environ.get('TMPDIR', None), tempfile.gettempdir())))
for q in candidates:
if q and path.startswith(q):
return True
return False