Added installation backup functionality

This commit is contained in:
Tristan Ancelet 2024-10-19 10:16:53 -05:00
parent 01a838c7f2
commit 7b61dd700a

View File

@ -161,12 +161,13 @@ def do_install(version)
File.open(installer_file, 'rb') do |file| File.open(installer_file, 'rb') do |file|
Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir]) Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir])
end end
if not $CONFIG[:keep_installer]
puts "do_install: Removing new installer (#{installer_file})"
File.unlink(installer_file)
end
end end
if not $CONFIG[:keep_installer]
puts "do_install: Removing new installer (#{installer_file})"
File.unlink(installer_file)
end
end end
def update_desktop_file def update_desktop_file
@ -194,32 +195,52 @@ def update_desktop_file
end end
def make_backup def make_backup
files = Array.new files = {
Dir.glob("#{$CONFIG[:discord_config_path]}/**").each{|item| files: Array.new,
if File.file?(item) or File.directory?(item) dirs: Array.new,
files << File.new(item) symlinks: Array.new
}
Dir.glob("#{$CONFIG[:discord_config_path].path}/**/**/**/**").each{ |item|
if File.file?(item)
files[:files] << item
elsif File.symlink?(item)
files[:symlinks] << item
elsif File.directory?(item)
files[:dirs] << item
end end
} }
Dir.glob("#{$CONFIG[:discord_path]}/**").each {|item|
if File.file?(item) or File.directory?(item) Dir.glob("#{$CONFIG[:discord_path].path}/**/**/**/**").each {|item|
files << File.new(item) if File.file?(item)
files[:files] << item
elsif File.symlink?(item)
files[:symlinks] << item
elsif File.directory?(item)
files[:dirs] << item
end end
} }
Dir.chdir(Dir.home) do Dir.chdir(Dir.home) do
File.open($CONFIG[:backup_filename], "wb") do |file| File.open($CONFIG[:backup_filename], "wb") do |backup_file|
Zlib::GzipWriter.wrap(file) do |gzip| Zlib::GzipWriter.wrap(backup_file) do |gzip|
Gem::Package::TarWriter.new(gzip) do |tar| Gem::Package::TarWriter.new(gzip) do |tar|
files.each do |file| files[:files].each do |file|
if File.file?(file) File.open(file, 'rb') { |file_to_archive|
content = file.read() contents = file_to_archive.read()
tar.add_file_simple(file.path.sub("#{Dir.home}/",''), file.stat.mode, content.length) do |io| tar.add_file_simple(file_to_archive.path.sub("#{Dir.home}/",''), file_to_archive.stat.mode, contents.length) do |io|
io.write(content) io.write(contents)
end end
elsif File.directory?(file) }
tar.mkdir(file.path.sub("#{Dir.home}/",""), file.stat.mode)
end
end end
files[:dirs].each do |dir|
tar.mkdir(dir.sub("#{Dir.home}/",""), File.stat(dir).mode)
end
files[:symlinks].each {|symlink|
tar.add_symlink(symlink.sub("#{Dir.home}/",""), File.readlink(symlink), File.lstat(symlink).mode)
}
end end
end end
end end