Added better write permission handling for .python_history

This commit is contained in:
Aurora Lanes 2020-01-27 19:50:35 +00:00 committed by GitHub
parent b23402b183
commit 96820cea3e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 0 deletions

View File

@ -448,6 +448,16 @@ def enablerlcompleter():
# home directory does not exist or is not writable # home directory does not exist or is not writable
# https://bugs.python.org/issue19891 # https://bugs.python.org/issue19891
pass 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) atexit.register(write_history)