debug-viewer: Copy log files in temporaries before using them

They are mmap'ed and it gets wrong if the file is changed.
There is high probablility the user will generate new logs while
inspecting some logs in the same file
This commit is contained in:
Thibault Saunier 2018-04-18 09:34:57 -03:00
parent 771f27b44b
commit ad886c288c

View file

@ -20,6 +20,9 @@
"""GStreamer Debug Viewer GUI module."""
import os.path
import tempfile
import shutil
from bisect import bisect_right, bisect_left
import logging
@ -231,6 +234,7 @@ class Window (object):
self.logger = logging.getLogger("ui.window")
self.app = app
self.tmpfile = None
self.dispatcher = None
self.info_widget = None
self.progress_dialog = None
@ -937,6 +941,7 @@ class Window (object):
if self.log_file is not None:
for feature in self.features:
feature.handle_detach_log_file(self, self.log_file)
self.tmpfile = None
if filename is None:
if self.dispatcher is not None:
@ -945,6 +950,9 @@ class Window (object):
self.log_file = None
self.actions.groups["RowActions"].props.sensitive = False
else:
self.tmpfile = tempfile.NamedTemporaryFile()
shutil.copyfile(filename, self.tmpfile.name)
filename = self.tmpfile.name
self.logger.debug("setting log file %r", filename)
try: