ultralytics 8.2.41 fix HUB unzip subdirectory bug (#13913)

This commit is contained in:
Glenn Jocher 2024-06-23 21:15:57 +02:00 committed by GitHub
parent 9362e759f7
commit e30b7c24f2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 7 deletions

View file

@ -168,13 +168,15 @@ def unzip_file(file, path=None, exclude=(".DS_Store", "__MACOSX"), exist_ok=Fals
files = [f for f in zipObj.namelist() if all(x not in f for x in exclude)]
top_level_dirs = {Path(f).parts[0] for f in files}
if len(top_level_dirs) > 1 or (len(files) > 1 and not files[0].endswith("/")):
# Zip has multiple files at top level
path = extract_path = Path(path) / Path(file).stem # i.e. ../datasets/coco8
else:
# Decide to unzip directly or unzip into a directory
unzip_as_dir = len(top_level_dirs) == 1 # (len(files) > 1 and not files[0].endswith("/"))
if unzip_as_dir:
# Zip has 1 top-level directory
extract_path = path # i.e. ../datasets
path = Path(path) / list(top_level_dirs)[0] # i.e. ../datasets/coco8
path = Path(path) / list(top_level_dirs)[0] # i.e. extract coco8/ dir to ../datasets/
else:
# Zip has multiple files at top level
path = extract_path = Path(path) / Path(file).stem # i.e. extract multiple files to ../datasets/coco8/
# Check if destination directory already exists and contains files
if path.exists() and any(path.iterdir()) and not exist_ok: