From 0bf3316aec0176a442cc4ed172778ef390b5125a Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Thu, 29 Aug 2019 17:27:07 +1000 Subject: [PATCH] FIX: race condition during deploys creating stylesheets In some cases stylesheet cache path may be missing, ensure it exists prior to writing stylesheet --- app/controllers/stylesheets_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/stylesheets_controller.rb b/app/controllers/stylesheets_controller.rb index aa25b78ec91..e5474da2ddb 100644 --- a/app/controllers/stylesheets_controller.rb +++ b/app/controllers/stylesheets_controller.rb @@ -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