8000 [3.14] gh-128066: Properly handle history file writes for RO fs on Py… · python/cpython@379805d · GitHub
[go: up one dir, main page]

Skip to content

Commit 379805d

Browse files
miss-islingtonfeohambv
authored
[3.14] gh-128066: Properly handle history file writes for RO fs on PyREPL (gh-134380) (gh-134385)
(cherry picked from commit c91ad5d) Co-authored-by: Chris Patti <feoh@feoh.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl>
1 parent 899ce7d commit 379805d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

Lib/_pyrepl/simple_interact.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import sys
3232
import code
3333
import warnings
34+
import errno
3435

3536
from .readline import _get_reader, multiline_input, append_history_file
3637

@@ -153,6 +154,7 @@ def maybe_run_command(statement: str) -> bool:
153154
append_history_file()
154155
except (FileNotFoundError, PermissionError, OSError) as e:
155156
warnings.warn(f"failed to open the history file for writing: {e}")
157+
156158
input_n += 1
157159
except KeyboardInterrupt:
158160
r = _get_reader()

Lib/site.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
import _sitebuiltins
7676
import _io as io
7777
import stat
78+
import errno
7879

7980
# Prefixes for site-packages; add additional prefixes like /usr/local here
8081
PREFIXES = [sys.prefix, sys.exec_prefix]
@@ -578,10 +579,15 @@ def register_readline():
578579
def write_history():
579580
try:
580581
readline_module.write_history_file(history)
581-
except (FileNotFoundError, PermissionError):
582+
except FileNotFoundError, PermissionError:
582583
# home directory does not exist or is not writable
583584
# https://bugs.python.org/issue19891
584585
pass
586+
except OSError:
587+
if errno.EROFS:
588+
pass # gh-128066: read-only file system
589+
else:
590+
raise
585591

586592
atexit.register(write_history)
587593

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fixes an edge case where PyREPL improperly threw an error when Python is
2+
invoked on a read only filesystem while trying to write history file
3+
entries.

0 commit comments

Comments
 (0)
0