2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-07-01 02:54:45 +08:00
|
|
|
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"))
|
2024-05-27 18:27:13 +08:00
|
|
|
FileUtils.mkdir_p(f) if Dir[f].blank?
|
2013-07-01 02:54:45 +08:00
|
|
|
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
|
2023-01-09 20:10:19 +08:00
|
|
|
|
2013-07-01 02:54:45 +08:00
|
|
|
def directory_cache
|
|
|
|
@directory_cache ||= {}
|
|
|
|
end
|
|
|
|
end
|