From 8696d6623a8bb02337f927af873477561d2461a3 Mon Sep 17 00:00:00 2001 From: Aurora Lanes <58722611+opensource-assist@users.noreply.github.com> Date: Fri, 31 Jan 2020 16:40:58 +0000 Subject: [PATCH 1/6] Update site.py --- Lib/site.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Lib/site.py b/Lib/site.py index 2c717987559e584..a0ab692cf413e91 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -448,6 +448,14 @@ def write_history(): # home directory does not exist or is not writable # https://bugs.python.org/issue19891 pass + except OSError: + if not os.access(history, os.W_OK): + print("Permission error!, unable to write .python_history") + if sys.platform == "linux": + chattrmsg = "Try running 'chattr -i " + history + "'" + print(chattrmsg) + else: + pass atexit.register(write_history) From 4b5d0511fa7bc95f8bcf9ae893af2ab834a20074 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 31 Jan 2020 16:48:05 +0000 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-01-31-16-48-04.bpo-39468.2geONV.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-01-31-16-48-04.bpo-39468.2geONV.rst diff --git a/Misc/NEWS.d/next/Library/2020-01-31-16-48-04.bpo-39468.2geONV.rst b/Misc/NEWS.d/next/Library/2020-01-31-16-48-04.bpo-39468.2geONV.rst new file mode 100644 index 000000000000000..7dc34d4417bbc2d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-01-31-16-48-04.bpo-39468.2geONV.rst @@ -0,0 +1 @@ +Improved permission handling in the site module' while writing into .python_history file \ No newline at end of file From b1d20e8659bc5123962bc334f7d04ecfda5b65e2 Mon Sep 17 00:00:00 2001 From: Aurora Lanes <58722611+opensource-assist@users.noreply.github.com> Date: Fri, 31 Jan 2020 16:53:39 +0000 Subject: [PATCH 3/6] Update site.py --- Lib/site.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index a0ab692cf413e91..687f0e5269f8b85 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -452,10 +452,10 @@ def write_history(): if not os.access(history, os.W_OK): print("Permission error!, unable to write .python_history") if sys.platform == "linux": - chattrmsg = "Try running 'chattr -i " + history + "'" - print(chattrmsg) - else: - pass + chattrmsg = "Try running 'chattr -i " + history + "'" + print(chattrmsg) + else: + pass atexit.register(write_history) From 087f9daed2a7af2e13a3d268fc40547ff0a12c8b Mon Sep 17 00:00:00 2001 From: Aurora Lanes <58722611+opensource-assist@users.noreply.github.com> Date: Fri, 31 Jan 2020 19:10:20 +0000 Subject: [PATCH 4/6] Update site.py --- Lib/site.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index 687f0e5269f8b85..d1d82f7af772241 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -444,18 +444,10 @@ def register_readline(): def write_history(): try: readline.write_history_file(history) - except (FileNotFoundError, PermissionError): + except (FileNotFoundError, PermissionError, OSError): # home directory does not exist or is not writable # https://bugs.python.org/issue19891 pass - except OSError: - if not os.access(history, os.W_OK): - print("Permission error!, unable to write .python_history") - if sys.platform == "linux": - chattrmsg = "Try running 'chattr -i " + history + "'" - print(chattrmsg) - else: - pass atexit.register(write_history) From 5f54e3abbfe8e483c7cda0bcafdb55baddde4a03 Mon Sep 17 00:00:00 2001 From: Aurora Lanes <58722611+opensource-assist@users.noreply.github.com> Date: Fri, 31 Jan 2020 20:17:13 +0000 Subject: [PATCH 5/6] Update site.py --- Lib/site.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Lib/site.py b/Lib/site.py index d1d82f7af772241..dd8701f3265880f 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -444,10 +444,13 @@ def register_readline(): def write_history(): try: readline.write_history_file(history) - except (FileNotFoundError, PermissionError, OSError): - # home directory does not exist or is not writable - # https://bugs.python.org/issue19891 - pass + except OSError as e: + if isinstance(e, (FileNotFoundError, PermissionError)) or e.errno == -1: + # home directory does not exist or is not writable + # https://bugs.python.org/issue19891 + pass + else: + raise atexit.register(write_history) From 4ce55b1fba31c2c91de07481cc1ec2457d4a53fb Mon Sep 17 00:00:00 2001 From: Aurora Lanes <58722611+opensource-assist@users.noreply.github.com> Date: Fri, 31 Jan 2020 20:21:45 +0000 Subject: [PATCH 6/6] Update site.py --- Lib/site.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/site.py b/Lib/site.py index dd8701f3265880f..a4cc6f45d064182 100644 --- a/Lib/site.py +++ b/Lib/site.py @@ -445,10 +445,12 @@ def write_history(): try: readline.write_history_file(history) except OSError as e: - if isinstance(e, (FileNotFoundError, PermissionError)) or e.errno == -1: + if isinstance(e, (FileNotFoundError, PermissionError)): # home directory does not exist or is not writable # https://bugs.python.org/issue19891 pass + elif isinstance(e, (OSError)) and e.errno == -1: + print("Warning: unable to write into .python_history") else: raise