Skip to content

Commit

Permalink
feat: handle non zip files with extension cases
Browse files Browse the repository at this point in the history
  • Loading branch information
anesson-cs committed Jul 10, 2023
1 parent 83e7a97 commit 506d693
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions eodag/plugins/download/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,21 @@ def download_request(
"Downloaded product is not a Zip File. Please check its file type before using it"
)
new_fs_path = fs_path[: fs_path.index(".zip")]
shutil.move(fs_path, new_fs_path)
# Check that the downloaded file is not a lone file and must not be placed in a directory
if os.path.isfile(fs_path) and getattr(
self.config, "outputs_in_folder", False
):
if not os.path.isdir(new_fs_path):
os.makedirs(new_fs_path)
shutil.move(fs_path, new_fs_path)
# WARNING: A strong assumption is made here: there is only one file in the directory
file_path = os.path.join(
new_fs_path, os.listdir(new_fs_path)[0]
)
new_file_path = file_path[: file_path.index(".zip")]
shutil.move(file_path, new_file_path)
else:
shutil.move(fs_path, new_fs_path)
product.location = path_to_uri(new_fs_path)
return new_fs_path

Expand All @@ -504,10 +518,8 @@ def download_request(
if not os.path.isdir(new_fs_path):
os.makedirs(new_fs_path)
shutil.move(fs_path, new_fs_path)
fs_path = new_fs_path

# do not try to extract or delete a directory
kwargs["extract"] = False
product.location = path_to_uri(new_fs_path)
return new_fs_path
product_path = self._finalize(
fs_path, progress_callback=progress_callback, **kwargs
)
Expand Down

0 comments on commit 506d693

Please sign in to comment.