Skip to content

Commit f2b269a

Browse files
committed
guard against permissions and EROFS errors
1 parent 3a27cb0 commit f2b269a

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

Lib/importlib/_bootstrap_external.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,18 +1259,25 @@ def set_data(self, path, data, *, _mode=0o666):
12591259
except FileExistsError:
12601260
# Probably another Python process already created the dir.
12611261
continue
1262-
except PermissionError as exc:
1263-
# Could be a permission error, read-only filesystem:
1262+
except OSError as exc:
1263+
# Could be a permission error or read-only filesystem (EROFS):
12641264
# just forget about writing the data.
1265-
_bootstrap._verbose_message('could not create {!r}: {!r}',
1266-
parent, exc)
1267-
return
1265+
from errno import EROFS
1266+
if isinstance(exc, PermissionError) or exc.errno == EROFS:
1267+
_bootstrap._verbose_message('could not create {!r}: {!r}',
1268+
parent, exc)
1269+
return
1270+
raise
12681271
try:
12691272
_write_atomic(path, data, _mode)
1270-
except PermissionError as exc:
1273+
except OSError as exc:
12711274
# Same as above: just don't write the bytecode.
1272-
_bootstrap._verbose_message('could not create {!r}: {!r}', path,
1273-
exc)
1275+
from errno import EROFS
1276+
if isinstance(exc, PermissionError) or exc.errno == EROFS:
1277+
_bootstrap._verbose_message('could not create {!r}: {!r}',
1278+
path, exc)
1279+
return
1280+
raise
12741281
else:
12751282
_bootstrap._verbose_message('created {!r}', path)
12761283

0 commit comments

Comments
 (0)