get_url - counterintuitive that it re-downloads if "dest" is a directory

Hello,

I noticed that my get_url calls were taking a long time even if the file
was already downloaded. After digging in the docs I found the following:

“If dest is a directory, the file will always be downloaded (regardless of the force option), but replaced only if the contents changed.”

IMO this is unintuitive because it should not matter whether the destination is a filename or directory. The situation is the same -
a file by that same name exists in a particular directory. Therefore the behavior should be the same, and controlled by other flags.

It would also be great if there were a way to compare checksums without downloading a file first - not sure
it’s possible but currently a large file would need to be downloaded first in order to check if it is identical to a
target - far from ideal given bandwidth and time constraints.

Regards,
–Ed

The issue is because you cannot know the hash of the file remotely, and when the destination is a directory the filename that is being written to is extracted from the headers of the response - so a request has to be made. I suppose that could be tweaked to do a HEAD call first, and only do the full GET request if the filename can’t be determined. If you’d like to open a github issue for that, feel free.

James - thanks for the explanation. I have created https://github.com/ansible/ansible/issues/7424
I think a HEAD call to get the filename first and avoid a full re-download makes a lot of sense.

Regards,
–Ed