-
Notifications
You must be signed in to change notification settings - Fork 596
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
Remove delete() call from CompressorFileStorage.get_available_name #1107
Conversation
I think it's worth testing (I know the current
They do this with the low-level primitives directly though, so they might run into different issues. I think it's fine to ignore them for this. |
No problem – added a small testcase which saves the same file and tests if the filename returned by |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 let's merge and get some people experiencing issues with this to test it!
django-compressor#1107 moved file-name-mangling avoidance into a `save` override, but the doc suggests calling `_save` which bypassess the new file-name-mangling-avoidance code. Updating a project to use django-compressor 4.0 that had a storages class which followed this doc resulted in mangled-named files appearing in the file system (and ultimately css changes not getting built/deployed, since the changes were in the mangled-name files while the rest of the process was using the "bare" name).
* Update doc in light of new mangled name avoidance #1107 moved file-name-mangling avoidance into a `save` override, but the doc suggests calling `_save` which bypassess the new file-name-mangling-avoidance code. Updating a project to use django-compressor 4.0 that had a storages class which followed this doc resulted in mangled-named files appearing in the file system (and ultimately css changes not getting built/deployed, since the changes were in the mangled-name files while the rest of the process was using the "bare" name). * Update changelog.txt
* Update doc in light of new mangled name avoidance django-compressor/django-compressor#1107 moved file-name-mangling avoidance into a `save` override, but the doc suggests calling `_save` which bypassess the new file-name-mangling-avoidance code. Updating a project to use django-compressor 4.0 that had a storages class which followed this doc resulted in mangled-named files appearing in the file system (and ultimately css changes not getting built/deployed, since the changes were in the mangled-name files while the rest of the process was using the "bare" name). * Update changelog.txt
This PR is an alternative to #1105 and #1100, and intends to fix #1099. It changes CompressorFileStorage:
CompressorFileStorage.get_available_name()
get_available_name
will sometimes return filenames with an underscore and a random string appended at the end to ensure uniquenesssave()
method to add one additional last step: if the filename contains an underscore then move it into the correct location.So, instead of deleting a file and then writing new data in the same filename, compressor would write the data in a temporary file, then move it to the correct place. Python docs say
os.replace
is an atomic operation, so this would avoid the brief moment of file not existing between delete and write.Notes:
GzipCompressorFileStorage
andBrotliCompressorFileStorage
override thesave
method again and do some more file IO. I'm not sure if we could run into race conditions there too.