FIX: race condition during deploys creating stylesheets

In some cases stylesheet cache path may be missing, ensure it exists
prior to writing stylesheet
This commit is contained in:
Sam Saffron 2019-08-29 17:27:07 +10:00
parent 098f9e8b5b
commit 0bf3316aec
1 changed files with 4 additions and 1 deletions

View File

@ -57,7 +57,9 @@ class StylesheetsController < ApplicationController
# Security note, safe due to route constraint
underscore_digest = digest ? "_" + digest : ""
location = "#{Rails.root}/#{Stylesheet::Manager::CACHE_PATH}/#{target}#{underscore_digest}#{extension}"
cache_path = "#{Rails.root}/#{Stylesheet::Manager::CACHE_PATH}"
location = "#{cache_path}/#{target}#{underscore_digest}#{extension}"
stylesheet_time = query.pluck(:created_at).first
@ -71,6 +73,7 @@ class StylesheetsController < ApplicationController
unless File.exist?(location)
if current = query.limit(1).pluck(source_map ? :source_map : :content).first
FileUtils.mkdir_p(cache_path)
File.write(location, current)
else
raise Discourse::NotFound