mirror of
https://github.com/discourse/discourse.git
synced 2025-06-06 13:06:56 +08:00
FIX: under concurrent usage booting rails could cause plugin corruption
Previously on boot we were always removing and adding the same pre-generated files and symlinks. This change attempts to avoid writing any automatically generated content if it is exactly what it should be on disk. This corrects issues where running a rails console can temporarily corrupt internal state in production.
This commit is contained in:
@ -543,9 +543,17 @@ class Plugin::Instance
|
|||||||
|
|
||||||
Discourse::Utils.execute_command('mkdir', '-p', target)
|
Discourse::Utils.execute_command('mkdir', '-p', target)
|
||||||
target << name.gsub(/\s/, "_")
|
target << name.gsub(/\s/, "_")
|
||||||
# TODO a cleaner way of registering and unregistering
|
|
||||||
Discourse::Utils.execute_command('rm', '-f', target)
|
symlink_is_correct = false
|
||||||
Discourse::Utils.execute_command('ln', '-s', public_data, target)
|
begin
|
||||||
|
symlink_is_correct = File.exists?(target) && File.readlink(target) == public_data
|
||||||
|
rescue Errno::EINVAL, Errno::ENOENT
|
||||||
|
end
|
||||||
|
|
||||||
|
if !symlink_is_correct
|
||||||
|
Discourse::Utils.execute_command('rm', '-f', target)
|
||||||
|
Discourse::Utils.execute_command('ln', '-s', public_data, target)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
ensure_directory(Plugin::Instance.js_path)
|
ensure_directory(Plugin::Instance.js_path)
|
||||||
@ -558,12 +566,22 @@ class Plugin::Instance
|
|||||||
contents << (is_dir ? "depend_on('#{f}')" : "require_asset('#{f}')")
|
contents << (is_dir ? "depend_on('#{f}')" : "require_asset('#{f}')")
|
||||||
end
|
end
|
||||||
|
|
||||||
File.delete(js_file_path) if js_asset_exists?
|
|
||||||
|
|
||||||
if contents.present?
|
if contents.present?
|
||||||
contents.insert(0, "<%")
|
contents.insert(0, "<%")
|
||||||
contents << "%>"
|
contents << "%>"
|
||||||
write_asset(js_file_path, contents.join("\n"))
|
|
||||||
|
contents = contents.join("\n")
|
||||||
|
|
||||||
|
if File.exists?(js_file_path)
|
||||||
|
current_contents = File.read(js_file_path)
|
||||||
|
if current_contents != contents
|
||||||
|
File.write(js_file_path, conten)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
write_asset(js_file_path, contents)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
File.delete(js_file_path) if js_asset_exists?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user