From 696a71bd8b6b27324ad236123df87f4578d245a7 Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Tue, 22 Oct 2024 14:14:27 -0500 Subject: [PATCH] Added backwards compat override to Dir class --- install-discord-linux.rb | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/install-discord-linux.rb b/install-discord-linux.rb index cf6b749..a8f0020 100755 --- a/install-discord-linux.rb +++ b/install-discord-linux.rb @@ -30,6 +30,15 @@ class Dir output_path end end + + ## For backwards compat + def chdir(dir = nil &block) + if dir.nil? + Dir.chdir(self, &block) + else + Dir.chdir(dir, &block) + end + end end class String @@ -170,7 +179,7 @@ class Installer file_contents = Net::HTTP.get(uri) output_file = "discord-#{version}.tar.gz" puts "download_installer: Output file will #{output_file}" - Dir.chdir($CONFIG[:install_dir]) do + $CONFIG[:install_dir].chdir do File.open(output_file, 'wb') do |file| file.write(file_contents) end @@ -181,7 +190,7 @@ class Installer def install installer_file = "discord-#{self.remote_version}.tar.gz" puts "do_install: Extracting new installer" - Dir.chdir($CONFIG[:install_dir]) do + $CONFIG[:install_dir].chdir do File.open(installer_file, 'rb') do |file| Gem::Package.new("").extract_tar_gz(file, $CONFIG[:install_dir]) end @@ -249,7 +258,7 @@ def make_backup end Dir.chdir(Dir.home) do - puts "make_backup: Beginning backup process (OUTPUT_FILE = #{Dir.getwd}/#{$CONFIG[:backup_filename]})" + puts "make_backup: Beginning backup process (OUTPUT_FILE = #{Dir.getwd/$CONFIG[:backup_filename]})" File.open($CONFIG[:backup_filename], "wb") do |backup_file| Zlib::GzipWriter.wrap(backup_file) do |gzip| Gem::Package::TarWriter.new(gzip) do |tar|