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
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cloudpathlib/cloudpath.py
Original file line number Diff line number Diff line change
@@ -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

for f in self.iterdir():
rel = str(self)
if not rel.endswith("/"):
rel = rel + "/"

rel_dest = str(f)[len(rel) :]
f.download_to(destination / rel_dest)
if rel_dest != "":
yuriolive marked this conversation as resolved.
Show resolved Hide resolved
f.download_to(destination / rel_dest)

return destination