You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Fix EEXIST errors in zipfile.py during extraction (#54)
When extracting zip archives, os.mkdir() could raise [Errno 17] EEXIST in two places: 1. makedirs() - A directory might already exist between the path_exists check and the os.mkdir() call, or be created by a prior extraction step. 2. _extract_member() - makedirs() may have already created a directory when building parent paths for a file entry, and then a separate directory entry for the same path triggers os.mkdir() again. Wrap both os.mkdir() calls in try/except OSError to handle this gracefully. Co-authored-by: Richard Taylor <RT@MacBookPro.lan> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1940,7 +1940,10 @@ class ZipFile:
|
||||
if parent:
|
||||
self.makedirs(parent) # Recursively create parent directories
|
||||
if not self.path_exists(path):
|
||||
os.mkdir(path)
|
||||
try:
|
||||
os.mkdir(path)
|
||||
except OSError:
|
||||
pass # Directory may already exist
|
||||
|
||||
def _extract_member(self, member, targetpath, pwd):
|
||||
"""Extract the ZipInfo object 'member' to a physical
|
||||
@@ -1972,7 +1975,10 @@ class ZipFile:
|
||||
# Handle directories
|
||||
if member.is_dir():
|
||||
if not self.path_isdir(targetpath):
|
||||
os.mkdir(targetpath)
|
||||
try:
|
||||
os.mkdir(targetpath)
|
||||
except OSError:
|
||||
pass # Directory may already exist from makedirs
|
||||
return targetpath
|
||||
|
||||
# Extract file
|
||||
|
||||
Reference in New Issue
Block a user