-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Cached download should be ignored if URL changes #349
Comments
While I think it's nice to use the timestamp of the destination file as the source for the |
An extension of this problem is that if you set |
Thanks for reporting this. I can see that this behaviour seems odd but everything works as it's supposed to. I understand that saving the URL in a map like it's done with the ETag would solve your particular example, but I'm not sure if it would address the root of the problem. It is true that the plugin uses the file's timestamp as a fallback if it cannot find an ETag for a given URL. However, if it can find one, it also skips downloading. Try this: Enable The problem is even worse here, by the way. If you do it the other way around, the plugin will not be able to know which of the two ETags is newer and will not overwrite version 6.46.0 with 6.44.0 like it would do if The only way to really solve the root cause would be to know if the task's inputs have changed since the last call, and if they had, skip any up-to-date checks and redownload the file. This might become possible in the future when Gradle's configuration cache becomes enabled by default, but it is certainly not possible now. From my point of view, if the user changes the URL of the file to download, they should manually remove the destination file or call the Let me know if this helps. I'm open to feedback and ideas! P.S.: I'm currently out of office with limited Internet access. It might take me some days to reply. |
This just seems like a bug in the cache implementation. It's only storing the URL but what matters is the ETag of the saved file. That's why you use the timestamp of the saved file for the Last-Modified handling, right? Without the saved file path, you can't make an accurate decision about when to invalidate the cache entries since you don't have enough information. You have the previous ETag of a URL, but you don't know if the file your using it to make decisions about was created from one of those URLs or not. Knowing the ETag of a URL at some point in time doesn't actually give you any useful information if it's not associated to a file you have locally. I think the ETag cache should be keyed by the saved path:
This has 2 effects:
That's fine if the person making the changes and doing the builds is always the same person, but it breaks down otherwise. What if my CI system has the download cached? What if another user in my team has the download cached and they didn't see that the URL changed? The only reliable way to handle that is to not cache at all or to always I'll change my tasks so they include the version number in the saved filename. I was trying to avoid it before so that when the code references the asset it can always use the generic name, but I don't actually need to reference it from the code right now. To circle back to one thing I said in the issue description - I think there should be an option to ignore Last-Modified if you're using an ETag and the server supplies one. That would put it in line with the HTTP behavior for
Which makes sense. If I say "I have a file that has this identifier, tell me if the one you have matches", then I don't care if it's older or newer. I only care whether the content is the same. It's like what a file archiver would do with checksums. |
download-task doesn't handle cached files with changed URLs well[1], so include the version in the saved file. 1. michel-kraemer/gradle-download-task#349
Describe the bug
If the URL has changed but the destination path hasn't then the existing destination file should be ignored for the purposes of
onlyIfModified
. Otherwise, if the timestamp of the new URL is older than the existing download, it will be skipped and you'll continue using the wrong download.Sample build script
If I run the task and then change
welcomeScreenVersion
to6.44.0
, the task is skipped:The text was updated successfully, but these errors were encountered: