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
# $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$
#
@ -384,61 +384,11 @@ end
def get_multi(subj, group)
print "Fetching multipart article: #{subj}\n"
if @config[group]["TEMPDIR"] == nil or @config[group]["TEMPDIR"] == ""
body = @articles.get_group_body(subj)
# should probably thread this too, but I never use this
if UUEncode.is_uuencoded(body)
filename = UUEncode.get_filename(body)
print " filename #{filename}\n"
unless check_ext(group, filename, "m", subj)
print " Skipping article...\n"
return false
end
print " UUDecoding...\n"
mode, filename, body = UUEncode.uudecode(body)
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
print " YDecoding...\n"
begin
mode, filename, body = YEnc.ydecode(body)
rescue YencError
# XXX if there is a yenc problem I want the data so I can research it
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"
return false
end
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
@ -452,6 +402,15 @@ def get_multi(subj, group)
return false
end
end
if @config[group]["TEMPDIR"] == nil or @config[group]["TEMPDIR"] == ""
bodyrest = @articles.get_group_body_rest(subj)
unless bodyrest
print " Skipping article...\n"
return false
end
body.concat(bodyrest)
else
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
@ -460,24 +419,44 @@ def get_multi(subj, group)
return false
end
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|
# imediately stop to continue with main program
Thread.stop
puts "inside thread\n"
if UUEncode.is_uuencoded(tbody)
print " UUDecoding...\n"
mode, filename, body = UUEncode.uudecode(tfile, tfileout)
elsif YEnc.is_yencoded(body)
if tfile
mode, filename, tbody = UUEncode.uudecode(tfile, tfileout)
else
mode, filename, tbody = UUEncode.uudecode(tbody)
end
elsif YEnc.is_yencoded(tbody)
print " YDecoding...\n"
mode, filename, body = YEnc.ydecode(tfile, tfileout)
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
end
end
if mode == false
print " Decoding failed skipping article...\n"
return false
end
if tfile
# horrible cheat to not lose the outputted file
tbody = tfileout.path
bodybase = tbody.sub(/\/[^\/]*$/, "/ripnewsdecode")
@ -487,12 +466,11 @@ def get_multi(subj, group)
end
File.move(tbody, "#{bodybase}-#{i}")
tbody = "#{bodybase}-#{i}"
file.close
fileout.close(false)
output_data(tsubj, mode, filename, tbody)
tfile.close
tfileout.close(false)
end
# thread could end here
output_data(tsubj, mode, filename, tbody)
end # thread end
@decode_threads.each{ |thr|
if thr.status == "sleep" # and fire up the threads again
@ -511,7 +489,6 @@ def get_multi(subj, group)
return false
end
end
end
def fill_preselector(group)
if @config[group].has_key?("-I")