From 96820cea3eb39d31798efcbcb4b3fb1ba667e3d7 Mon Sep 17 00:00:00 2001 From: Aurora Lanes <58722611+opensource-assist@users.noreply.github.com> Date: Mon, 27 Jan 2020 19:50:35 +0000 Subject: [PATCH] Added better write permission handling for .python_history --- Lib/site.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Lib/site.py b/Lib/site.py index 2c717987559..3bb55a5a086 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -448,6 +448,16 @@ def enablerlcompleter(): # home directory does not exist or is not writable # https://bugs.python.org/issue19891 pass + except OSError: + if sys.platform == "linux" and not os.access(history, os.W_OK): + if os.getuid() == 0: + chattrcmd = "chattr -i " + history + os.system(chattrcmd) + else + chattrmsg = "Permission error!, try running 'chattr -i " + history + "'" + print(chattrmsg) + else + print("An error occured while writing to .python_history") atexit.register(write_history)