Fix to check if command_history file exists prior to trying to read it

This commit is contained in:
Henrique 2019-11-23 16:31:21 -05:00
parent 01b40e2c36
commit 6d67286bd1

View File

@ -7,6 +7,7 @@ import mitmproxy.options
import mitmproxy.types
from mitmproxy import command
from mitmproxy import ctx
from mitmproxy.tools.console.commander.commander import CommandBuffer
@ -22,8 +23,10 @@ class CommandHistory:
self.filtered_commands: typing.Deque[str] = collections.deque()
self.filter_active: bool = True
_command_history_path = os.path.join(os.path.expanduser(mitmproxy.options.CONF_DIR), 'command_history')
_history_lines = open(_command_history_path, 'r').readlines()
_command_history_path = os.path.join(os.path.expanduser(ctx.options.confdir), 'command_history')
_history_lines = []
if os.path.exists(_command_history_path):
_history_lines = open(_command_history_path, 'r').readlines()
self.command_history_file = open(_command_history_path, 'w')