mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 23:26:27 +08:00
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
|