mirror of
https://github.com/OpenNebula/one.git
synced 2025-04-02 10:50:07 +03:00
feature #1303: make the uncompressor write to the fd
ruby 1.8.7 has a bug writting files (or pipes) to overcome it the file (or stdout) is opened in the downloader and then the uncompress command is started redirecting stdout to the descriptor. Pseudocode: if write_to_stdout? fd=dup(stdout) else fd=open(output_file) end exec("$UNCOMPRESSOR >&$fd")
This commit is contained in:
parent
df71bfa3ab
commit
a9f8634a29
@ -65,7 +65,7 @@ class Stream
|
||||
|
||||
def open_output_file
|
||||
if @to=='-'
|
||||
@output_file=STDOUT
|
||||
@output_file=STDOUT.dup
|
||||
else
|
||||
begin
|
||||
@output_file=File.open(@to, "w")
|
||||
@ -122,13 +122,11 @@ class Stream
|
||||
def set_compress(header)
|
||||
t=type(header)
|
||||
|
||||
compr=TYPES[t]
|
||||
compr=TYPES[t]||"cat"
|
||||
|
||||
if compr
|
||||
@uncompress_proc=Open3.popen3(compr)
|
||||
else
|
||||
@uncompress_proc=Open3.popen3("cat")
|
||||
end
|
||||
compr="#{compr} >&#{@output_file.fileno}"
|
||||
|
||||
@uncompress_proc=Open3.popen3(compr)
|
||||
|
||||
@compr_in=@uncompress_proc[0]
|
||||
@compr_out=@uncompress_proc[1]
|
||||
@ -149,20 +147,8 @@ class Stream
|
||||
end
|
||||
end
|
||||
|
||||
def http_downloader(url)
|
||||
uri=URI(url)
|
||||
|
||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||
request=Net::HTTP::Get.new(uri.request_uri)
|
||||
|
||||
http.request(request) do |response|
|
||||
response.read_body(&process)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def wget_downloader(url)
|
||||
@popen=Open3.popen3("wget -O - '#{url}'")
|
||||
@popen=Open3.popen3("wget -O - '#{url}'")
|
||||
@popen[0].close
|
||||
@popen[1]
|
||||
end
|
||||
@ -215,14 +201,15 @@ class Stream
|
||||
open_output_file
|
||||
|
||||
set_compress(header)
|
||||
start_file_writer
|
||||
|
||||
download_stderr=""
|
||||
|
||||
process(header)
|
||||
|
||||
while(!io.eof?)
|
||||
@popen[2].read_nonblock(BLOCK_SIZE, download_stderr) if @popen
|
||||
if defined?(@popen)
|
||||
@popen[2].read_nonblock(BLOCK_SIZE, download_stderr)
|
||||
end
|
||||
data=io.read(BLOCK_SIZE)
|
||||
process(data)
|
||||
end
|
||||
@ -231,8 +218,6 @@ class Stream
|
||||
|
||||
@compr_in.close_write
|
||||
|
||||
@writer_thread.join
|
||||
|
||||
check_hashes
|
||||
|
||||
postprocess if @to!='-'
|
||||
|
Loading…
x
Reference in New Issue
Block a user