-
Notifications
You must be signed in to change notification settings - Fork 346
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
Drop trailing slash of prefix in #get_local_files #425
Drop trailing slash of prefix in #get_local_files #425
Conversation
2a67010
to
bbd258a
Compare
The local filesystem glob in `AssetSync::Storage#get_local_files` uses fuzzy matching when config.prefix is present. This can present a problem in some cases, as it doesn't allow for distinguishing between (e.g.) a folder called `assets/` and another folder called `assets-temp/`. A situation could arise where the latter folder has thousands/millions of files and we mistakenly publish local-only files, or worse we could clobber another directory in the bucket managed in a completely different context. This change allows developers to be more specific in their `config.prefix` by using a trailing slash for their folder name.
bbd258a
to
26c45ed
Compare
Can you explain this PR in usage aspect? |
Apologies. I am actually still gathering years-old context, and am attempting to forward-port a patch our org has maintained on top of v1.1.0. It's possible that the patch is not actually necessary. I will circle back in the next few days to find out and update this PR when I've done so. Thanks for taking a look. |
I believe the reason this is necessary is due to the following scenario:
This is relevant because it would mean that if you don't set the
The trailing slash in the asset prefix would mean that the list of local files would include a double slash. For example: > Dir['tmp//**/**']
=> ["tmp//cache", ...] The reason this is problematic is because the diff between asset_sync/lib/asset_sync/storage.rb Line 320 in 4deb6ff
remote_files will contain a single slash while local_files will contain a double slash. This would result in files being unnecessarily uploaded. For example:
Even though this file does exist in the remote bucket, it will still be uploaded because of the trailing slash in the asset prefix. We could avoid this by not using a trailing slash and ensuring that the bucket prefix only ever matches 1 directory, but it's risky and prone to human error. Protecting against this scenario with this PR I think would be better long-term. Thoughts? |
Can you guys test this PR for a while and see if it works? |
We've been using this patch since 2017 on our primary production application. I can confirm it's been working for us since then. Let me know if there's anything other data / specific tests you'd like to run. Thanks! |
There should be test cases for |
Assuming specs look reasonable, I can squash the commits prior to merge. |
squash is not needed, anything else that should be changed/added before I merge? |
Nope, all set on our end! |
I should make a new release in a week |
No worries, thanks! |
The local filesystem glob in
AssetSync::Storage#get_local_files
uses fuzzy matching whenconfig.prefix
is present. This can present a problem in some cases, as it doesn't allow for distinguishing between (e.g.) a folder calledassets/
and another folder calledassets-temp/
. A situation could arise where the latter folder has thousands/millions of files and we mistakenly publish local-only files, or worse we could clobber another directory in the bucket managed in a completely different context.This change allows developers to be more specific in their
config.prefix
by using a trailing slash for their folder name.