mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 01:32:23 +08:00
FIX: Write stylesheet cache atomically (#28457)
In some situations, the filesystem cache will be read and persisted to the database. If the file being read is still being written, then that can lead to empty/partial caches being stored in the database. This commit ensures that cannot happen by switching to our `atomic_write_file` helper (which writes to a temp file, and then does an atomic `mv` operation to move it to the destination)
This commit is contained in:
parent
9dd47ca755
commit
150f5694dc
|
@ -71,7 +71,7 @@ class StylesheetsController < ApplicationController
|
|||
unless File.exist?(location)
|
||||
if current = query.pick(source_map ? :source_map : :content)
|
||||
FileUtils.mkdir_p(cache_path)
|
||||
File.write(location, current)
|
||||
Discourse::Utils.atomic_write_file(location, current)
|
||||
else
|
||||
raise Discourse::NotFound
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user