creating raw images for QEMU

This commit is contained in:
Artur Gurgul 2025-08-11 14:18:59 +02:00
parent 3b9e0a1f33
commit 49cc960703
13 changed files with 164 additions and 17 deletions

View file

@ -1,21 +1,33 @@
require 'uri'
require 'addressable/uri'
require 'user'
require 'fileutils'
require 'open-uri'
module Downloader
# use_cache => save in the home and return path to it
# forced => download even if the file exists in the cache, saves to chace if use_cache == true
def self.get(url, use_cache = true, forced = false)
puts "downloading..."
puts url
uri = Addressable::URI.parse(url)
path = File.join("#{ENV["HOME"]}/.cache/dat/downloads/", uri.domain, uri.path)
path = File.join(User.cache_path, "downloads", uri.domain, uri.path)
#uri = URI.parse(url)
#file_name = File.basename(uri.path)
puts "Download path: #{path}"
# Ensure the directory exists
dir = File.dirname(path)
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
unless File.exist?(path)
puts "File does not exist, downloading..."
URI.open(uri) do |input|
File.open(path, 'wb') do |output|
IO.copy_stream(input, output)
end
end
end
yield path
end
end