summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/cmd2.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 8310da93..f7c91172 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -34,6 +34,7 @@ import cmd
import glob
import inspect
import os
+import pathlib
import pickle
import re
import sys
@@ -3465,29 +3466,29 @@ class Cmd(cmd.Cmd):
self.persistent_history_file = hist_file
return
- hist_file = os.path.expanduser(hist_file)
+ histpath = pathlib.Path(hist_file).expanduser().resolve()
# first we try and unpickle the history file
history = History()
# on Windows, trying to open a directory throws a permission
# error, not a `IsADirectoryError`. So we'll check it ourselves.
- if os.path.isdir(hist_file):
+ if histpath.is_dir():
msg = "persistent history file '{}' is a directory"
- self.perror(msg.format(hist_file))
+ self.perror(msg.format(histpath))
return
try:
- with open(hist_file, 'rb') as fobj:
+ with open(str(histpath), 'rb') as fobj:
history = pickle.load(fobj)
except (FileNotFoundError, KeyError, EOFError):
pass
except OSError as ex:
msg = "can not read persistent history file '{}': {}"
- self.perror(msg.format(hist_file, ex), traceback_war=False)
+ self.perror(msg.format(histpath, ex), traceback_war=False)
return
self.history = history
- self.persistent_history_file = hist_file
+ self.persistent_history_file = str(histpath)
# populate readline history
if rl_type != RlType.NONE: