[3007.x] Don't unnecessarily download remote sources to cache
What does this PR do?
Makes file.managed check if an existing file's contents match the expected ones early (for remote sources with known source_hash). If they do, forces replace to false and thus skips fetching the file to cache.
What issues does this PR fix or reference?
Fixes: https://github.com/saltstack/salt/issues/66342 Ref: https://github.com/saltstack/salt/issues/64373
Previous Behavior
Essentially manages both intended file and file in cache, wastes resources.
New Behavior
Only manages intended file.
Merge requirements satisfied?
[NOTICE] Bug fixes or features added to Salt require tests.
- [x] Docs
- [x] Changelog - https://docs.saltproject.io/en/master/topics/development/changelog.html
- [x] Tests written/updated
Commits signed with GPG?
Yes
@dwoz Yes, it has been this way since Salt's inception I think.
I opted to submit this for 3007 since it would require some attention if it was merged forward instead (in regards to file signature verification: it would silently forget about signature verification on the source_hash file). A backport should work fine if one just removes the new parameters from the call to file.get_source_sum.
@lkubb Can you please backport this too?
@dwoz Sure. :)