Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: download_to function tried to download path files #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

yuriolive
Copy link

@yuriolive yuriolive commented Feb 5, 2022

In download directory cases, the download_to function was running in an infinite loop. For example:

We have a s3 example bucket with 1 one file in it:
s3://example/test_file.txt

The function iterdir() will return:

s3://example/
s3://example/test_file.txt

In this case the rel_dest variable will be an empty string for the first case and test_file.txt for the second one.

The f.download_to(destination / rel_dest) will call the download_to function with re_dest as empty, causing an infinite loop.

The solution was to just verify if re_dest is not empty.

I also added the parents=True to destination.mkdir so it will create the directory even if is missing intermediate parent directories.

cloudpathlib/cloudpath.py Outdated Show resolved Hide resolved
@@ -594,14 +594,15 @@ def download_to(self, destination: Union[str, os.PathLike]) -> Path:
destination = destination / self.name
return self.client._download_file(self, destination)
else:
destination.mkdir(exist_ok=True)
destination.mkdir(parents=True, exist_ok=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not totally bought in on automatically creating missing parents by default. I believe most things (unix programs and Python libraries) do not normally do this.

A related consideration here is to maybe add a parents parameter to download_to?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the commit to pass parents as a parameter to download_to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants