This repository was archived by the owner on Oct 5, 2018. It is now read-only.
Prevent deleting processing image while attachment is processing#137
Open
cgunther wants to merge 1 commit intojrgifford:masterfrom
Open
Prevent deleting processing image while attachment is processing#137cgunther wants to merge 1 commit intojrgifford:masterfrom
cgunther wants to merge 1 commit intojrgifford:masterfrom
Conversation
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 when processing_image_url is set. This leads to Paperclip deleting the processing image, thinking it is the style for the attachment. 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 as exists? previously returned true even if the style was not yet processed. 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.
Collaborator
|
hey @cgunther this is really useful! Would you mind taking a look at the rails 3.2 failures? This is telling me maybe we should stop supporting Rails < 4 but if it's an easy fix it'd be welcome |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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_urlis 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.