fix threading problems?

This commit is contained in:
Ward Wouts 2005-02-02 09:11:28 +00:00
parent a06ece8c56
commit 3767681c02

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w #!/usr/local/bin/ruby -w
# $Dwarf: ripnews.rb,v 1.94 2005/02/01 19:35:49 ward Exp $ # $Dwarf: ripnews.rb,v 1.95 2005/02/01 22:09:22 ward Exp $
# $Source$ # $Source$
# #
@ -384,11 +384,8 @@ end
def get_multi(subj, group) def get_multi(subj, group)
print "Fetching multipart article: #{subj}\n" print "Fetching multipart article: #{subj}\n"
if @config[group]["TEMPDIR"] == nil or @config[group]["TEMPDIR"] == "" body = @articles.get_group_body_first(subj)
body = @articles.get_group_body(subj) if UUEncode.is_uuencoded(body) or YEnc.is_yencoded(body)
# should probably thread this too, but I never use this
if UUEncode.is_uuencoded(body) if UUEncode.is_uuencoded(body)
filename = UUEncode.get_filename(body) filename = UUEncode.get_filename(body)
print " filename #{filename}\n" print " filename #{filename}\n"
@ -396,8 +393,6 @@ def get_multi(subj, group)
print " Skipping article...\n" print " Skipping article...\n"
return false return false
end end
print " UUDecoding...\n"
mode, filename, body = UUEncode.uudecode(body)
elsif YEnc.is_yencoded(body) elsif YEnc.is_yencoded(body)
print "yencc\n" print "yencc\n"
filename = YEnc.get_filename(body) filename = YEnc.get_filename(body)
@ -406,52 +401,16 @@ def get_multi(subj, group)
print " Skipping article...\n" print " Skipping article...\n"
return false return false
end end
print " YDecoding...\n" end
begin
mode, filename, body = YEnc.ydecode(body) if @config[group]["TEMPDIR"] == nil or @config[group]["TEMPDIR"] == ""
rescue YencError bodyrest = @articles.get_group_body_rest(subj)
# XXX if there is a yenc problem I want the data so I can research it unless bodyrest
output_data(subj, 0600, "YencProblem", body)
# XXX return succes even though it's not true
return true
rescue PermError
print "#{$!}\n"
print " Skipping article...\n" print " Skipping article...\n"
return false return false
end end
body.concat(bodyrest)
else else
print " Unknown encoding (not UU, not yEnc), skipping...\n"
return false
end
if mode == false
print " Decoding failed skipping article...\n"
return false
end
output_data(subj, mode, filename, body)
# end of thread
return true
else
body = @articles.get_group_body_first(subj)
if UUEncode.is_uuencoded(body) or YEnc.is_yencoded(body)
if UUEncode.is_uuencoded(body)
filename = UUEncode.get_filename(body)
print " filename #{filename}\n"
return false unless check_ext(group, filename, "m", subj)
unless check_ext(group, filename, "m", subj)
print " Skipping article...\n"
return false
end
elsif YEnc.is_yencoded(body)
print "yencc\n"
filename = YEnc.get_filename(body)
print "filename #{filename}\n"
unless check_ext(group, filename, "m", subj)
print " Skipping article...\n"
return false
end
end
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"]) file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"} body.collect{|x| file.print "#{x}\n"}
@ -460,24 +419,44 @@ def get_multi(subj, group)
return false return false
end end
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"]) fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
end
# I think a thread should start about here @decode_threads << Thread.new(body, file, fileout, subj) do |tbody, tfile, tfileout, tsubj|
@decode_threads << Thread.new(body, file, fileout, subj) do |tbody, tfile,tfileout, tsubj| # imediately stop to continue with main program
# imediately stop to continue with main program Thread.stop
Thread.stop puts "inside thread\n"
puts "inside thread\n" if UUEncode.is_uuencoded(tbody)
if UUEncode.is_uuencoded(tbody) print " UUDecoding...\n"
print " UUDecoding...\n" if tfile
mode, filename, body = UUEncode.uudecode(tfile, tfileout) mode, filename, tbody = UUEncode.uudecode(tfile, tfileout)
elsif YEnc.is_yencoded(body) else
print " YDecoding...\n" mode, filename, tbody = UUEncode.uudecode(tbody)
mode, filename, body = YEnc.ydecode(tfile, tfileout)
end end
if mode == false elsif YEnc.is_yencoded(tbody)
print " Decoding failed skipping article...\n" print " YDecoding...\n"
begin
if tfile
mode, filename, tbody = YEnc.ydecode(tfile, tfileout)
else
mode, filename, tbody = YEnc.ydecode(tbody)
end
rescue YencError
# XXX if there is a yenc problem I want the data so I can research it
output_data(subj, 0600, "YencProblem", tbody)
# XXX return succes even though it's not true
return true
rescue PermError
print "#{$!}\n"
print " Skipping article...\n"
return false return false
end end
end
if mode == false
print " Decoding failed skipping article...\n"
return false
end
if tfile
# horrible cheat to not lose the outputted file # horrible cheat to not lose the outputted file
tbody = tfileout.path tbody = tfileout.path
bodybase = tbody.sub(/\/[^\/]*$/, "/ripnewsdecode") bodybase = tbody.sub(/\/[^\/]*$/, "/ripnewsdecode")
@ -487,29 +466,27 @@ def get_multi(subj, group)
end end
File.move(tbody, "#{bodybase}-#{i}") File.move(tbody, "#{bodybase}-#{i}")
tbody = "#{bodybase}-#{i}" tbody = "#{bodybase}-#{i}"
file.close tfile.close
fileout.close(false) tfileout.close(false)
output_data(tsubj, mode, filename, tbody)
end end
# thread could end here output_data(tsubj, mode, filename, tbody)
end # thread end
@decode_threads.each{ |thr| @decode_threads.each{ |thr|
if thr.status == "sleep" # and fire up the threads again if thr.status == "sleep" # and fire up the threads again
thr.run thr.run
elsif thr.status == "false" # remove finished threads elsif thr.status == "false" # remove finished threads
thr.join thr.join
else else
p thr.status p thr.status
end end
} }
puts "ouside thread\n" puts "ouside thread\n"
return true return true
else else
print " Unknown encoding (not UU, not yEnc), skipping...\n" print " Unknown encoding (not UU, not yEnc), skipping...\n"
return false return false
end
end end
end end