This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
Prevent deleting processing image while attachment is processing #137
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
On destroying a model, Paperclip will delete any styles for which
exists?
returns true.exists?
checked the path, which would point to the processing image while the attachment was processing whenprocessing_image_url
is set. This leads to Paperclip deleting theprocessing image, thinking it is the style for the attachment.
Given:
When deleting a photo that was not yet processed, you'd see this in your logs as Paperclip deleted both the original (correctly) and the thumbnail processing image (incorrectly):
This patch overrides Paperclip's
exists?
method so that if the given style is processing,exists?
will always return false, thus preventing Paperclip from trying to delete the processing image. This is not backwards compatible asexists?
previously returned true even if thestyle was not yet processed.
Previously:
Now:
This may still leave some orphaned files as if the model is destroyed while the processing job is currently running, no styles will be deleted, but some styles may have already been written to disk as the job runs.
While it's a small window to delete the model in before the background job finishes running, it's a pretty big issue that the processing images that you think are safe in your app may be deleted and will now 404 on future requests to them until you deploy again, adding the processing images, only for them to be deleted again when someone deletes the model before the background job finishes.