Skip to content

Commit

Permalink
debian: remove temporary files as fast as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 8, 2025
1 parent 49f0aed commit 979ec96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
29 changes: 21 additions & 8 deletions lib/rubygems-requirements-system/platform/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ module Platform
class Base
include Gem::UserInteraction

def initialize
@temporary_files = []
end

def target?(platform)
raise NotImpelementedError
end
Expand Down Expand Up @@ -85,13 +81,30 @@ def have_priviledge?
super_user?
end

def temporary_file_scope
@temporary_files = []
begin
yield
ensure
@temporary_files.each(&:close!)
end
end

def create_temporary_file(basename)
file = Tempfile.new(basename)
@temporary_files << file
file
end

def install_package(package)
prepare_command_lines(package).each do |command_line|
unless run_command_line(package, "prepare", command_line)
return false
temporary_file_scope do
prepare_command_lines(package).each do |command_line|
unless run_command_line(package, "prepare", command_line)
return false
end
end
run_command_line(package, "install", install_command_line(package))
end
run_command_line(package, "install", install_command_line(package))
end

def run_command_line(package, action, command_line)
Expand Down
9 changes: 5 additions & 4 deletions lib/rubygems-requirements-system/platform/debian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ def prepare_command_lines(package)
def install_command_line(package)
if package.start_with?("https://")
package_url = resolve_package_url_template(package)
local_package = Tempfile.new([
"rubygems-requirements-system-debian",
File.extname(package),
])
temporary_file_base_name = [
"rubygems-requirements-system-debian",
File.extname(package),
]
local_package = create_temporary_file(temporary_file_base_name)
URI.open(package_url) do |response|
IO.copy_stream(response, local_package)
end
Expand Down

0 comments on commit 979ec96

Please sign in to comment.