mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 06:13:47 +08:00
dbafa10b3c
This has been split out from https://github.com/discourse/discourse/pull/28051 so we can use this same code in plugin specs before merging the core PR, adds some helpers for creating local backup temp files and cleaning them up.
30 lines
724 B
Ruby
30 lines
724 B
Ruby
# frozen_string_literal: true
|
|
|
|
module BackupsHelpers
|
|
def setup_local_backups
|
|
root_directory = Dir.mktmpdir
|
|
SiteSetting.backup_location = BackupLocationSiteSetting::LOCAL
|
|
root_directory
|
|
end
|
|
|
|
def teardown_local_backups(root_directory:)
|
|
FileUtils.remove_dir(root_directory, true)
|
|
end
|
|
|
|
def create_local_backup_file(root_directory:, db_name:, filename:, last_modified:, size_in_bytes:)
|
|
path = File.join(root_directory, db_name)
|
|
Dir.mkdir(path) unless Dir.exist?(path)
|
|
|
|
path = File.join(path, filename)
|
|
return if File.exist?(path)
|
|
|
|
FileUtils.touch(path)
|
|
File.truncate(path, size_in_bytes)
|
|
|
|
time = Time.parse(last_modified)
|
|
File.utime(time, time, path)
|
|
|
|
path
|
|
end
|
|
end
|