diff --git a/src/commands/install.cr b/src/commands/install.cr index ceb7d60..0b24e96 100644 --- a/src/commands/install.cr +++ b/src/commands/install.cr @@ -48,6 +48,21 @@ module Crimson::Commands end {% end %} + installed = false + path = uninitialized Path + archive = uninitialized File + + Process.on_interrupt do + if archive + archive.close rescue nil + archive.delete rescue nil + end + + FileUtils.rm_rf path if path && !installed + STDERR << "\e[?25h" + exit 1 + end + path = ENV::LIBRARY_CRYSTAL / version puts "Installing Crystal version: #{version}" verbose { "ensuring directory: #{path}" } @@ -65,20 +80,12 @@ module Crimson::Commands archive = File.open path / "crystal-#{version}-#{ENV::TARGET_IDENTIFIER}", mode: "w" verbose { "location: #{archive.path}" } - installed = false source = "https://github.com/crystal-lang/crystal/releases/download/" \ "#{version}/crystal-#{version}-#{ENV::TARGET_IDENTIFIER}" puts "Downloading sources..." verbose { source } - at_exit do - archive.close unless archive.closed? - archive.delete rescue nil - FileUtils.rm_rf path unless installed - STDERR << "\e[?25h" - end - Crest.get source do |res| IO.copy res.body_io, archive archive.close