mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:40:00 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
25 lines
556 B
Ruby
25 lines
556 B
Ruby
# frozen_string_literal: true
|
|
|
|
module DirectoryHelper
|
|
|
|
def tmp_directory(prefix)
|
|
directory_cache[prefix] ||= begin
|
|
f = File.join(Rails.root, 'tmp', Time.now.strftime("#{prefix}%Y%m%d%H%M%S"))
|
|
FileUtils.mkdir_p(f) unless Dir[f].present?
|
|
f
|
|
end
|
|
end
|
|
|
|
def remove_tmp_directory(prefix)
|
|
tmp_directory_name = directory_cache[prefix] || ''
|
|
directory_cache.delete(prefix)
|
|
FileUtils.rm_rf(tmp_directory_name) if Dir[tmp_directory_name].present?
|
|
end
|
|
|
|
private
|
|
def directory_cache
|
|
@directory_cache ||= {}
|
|
end
|
|
|
|
end
|