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,7 +161,6 @@ 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
end
if not $CONFIG[:keep_installer] if not $CONFIG[:keep_installer]
puts "do_install: Removing new installer (#{installer_file})" puts "do_install: Removing new installer (#{installer_file})"
@ -169,6 +168,8 @@ def do_install(version)
end end
end end
end
def update_desktop_file def update_desktop_file
file_needs_updating = true file_needs_updating = true
puts "update_desktop_file: Checking if desktop entry needs updating" puts "update_desktop_file: Checking if desktop entry needs updating"
@ -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
files[:dirs].each do |dir|
tar.mkdir(dir.sub("#{Dir.home}/",""), File.stat(dir).mode)
end 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