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

Fixed bug with the difference of key format between generate_cache_id and clean_cache! #2036

Conversation

t-oginogin
Copy link
Contributor

Hello, I found bug in clean_cache! method.

CarrierWave::Storage::File.clean_cache! always cleans all file caches before expired.

Because CarrierWave::Storage::File.clean_cache! doesn't refer TIMEINT but PID.
CarrierWave::Uploader::Cache.generate_cache_id returns key format like "TIMEINT-PID-COUNTER-RND".
It should refer 1st element(TIMEINT).
But CarrierWave::Storage::File.clean_cache! try match /(\d+)-\d+-\d+$/ .
So it matched 2nd element(PID) which shows the time when cache directory created.
And Time.at(*time) always returns like 1970/mm/dd, then cache directory is all expired.

@mshibuya
Copy link
Member

mshibuya commented Oct 8, 2016

Could you write a spec that will fail without this fix?

@t-oginogin
Copy link
Contributor Author

@mshibuya The spec included this commit( spec/storage/file_spec.rb ) is fail without this fix.
The key format of expected data was wrong before this fix.

Expected data(File) Result
"#{five_days_ago_int}-234-2213" (expected data is wrong) success
"#{five_days_ago_int}-234-1234-2213" (expected data is right) fail

But spec/storage/fog_helper.rb is not fail. Because Strage::Fog.clean_cache! matches wrong key format too.

Expected data(Fog) Result
"#{five_days_ago_int}-234-2213" (expected data is wrong) success
"#{five_days_ago_int}-234-1234-2213" (expected data is right) success
  • without this fix
Class Regexp matched
File /(\d+)-\d+-\d+$/ (PID)-COUNTER-RND
Fog /(\d+)-\d+-\d+/ (TIMEINT)-PID-COUNTER
  • this fix
Class Regexp matched
File /(\d+)-\d+-\d+-\d+/ (TIMEINT)-PID-COUNTER-RND
Fog /(\d+)-\d+-\d+-\d+/ (TIMEINT)-PID-COUNTER-RND

Does that answer your question?

@mshibuya
Copy link
Member

mshibuya commented Oct 8, 2016

I know the purpose of this fix, but we need unit test to make sure this bug never occurs in the future.
All specs are passing right now, so it means our test isn't fully covered to detect this problem.

@t-oginogin
Copy link
Contributor Author

I understand it means.
I try to write spec.

@t-oginogin
Copy link
Contributor Author

@mshibuya I wrote specs to detect this problem.

@mshibuya mshibuya merged commit fa9d1e3 into carrierwaveuploader:master Oct 9, 2016
@mshibuya
Copy link
Member

mshibuya commented Oct 9, 2016

Perfect, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants