Skip to content

Commit cbce6d3

Browse files
committed
guard against permissions and EROFS errors
1 parent 482a716 commit cbce6d3

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Lib/importlib/_bootstrap_external.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -989,18 +989,26 @@ def set_data(self, path, data, *, _mode=0o666):
989989
except OSError as exc:
990990
# Could be a permission error or read-only filesystem (EROFS):
991991
# just forget about writing the data.
992-
from errno import EROFS
993-
if isinstance(exc, PermissionError) or exc.errno == EROFS:
992+
from errno import EACCES, EROFS
993+
994+
if (
995+
isinstance(exc, PermissionError)
996+
or exc.errno in {EACCES, EROFS}
997+
):
994998
_bootstrap._verbose_message('could not create {!r}: {!r}',
995-
parent, exc)
999+
parent, exc)
9961000
return
9971001
raise
9981002
try:
9991003
_write_atomic(path, data, _mode)
10001004
except OSError as exc:
10011005
# Same as above: just don't write the bytecode.
1002-
from errno import EROFS
1003-
if isinstance(exc, PermissionError) or exc.errno == EROFS:
1006+
from errno import EACCES, EROFS
1007+
1008+
if (
1009+
isinstance(exc, PermissionError)
1010+
or exc.errno in {EACCES, EROFS}
1011+
):
10041012
_bootstrap._verbose_message('could not create {!r}: {!r}',
10051013
path, exc)
10061014
return

0 commit comments

Comments
 (0)