bit of a cleanup and make a race condition in get_max_file_length less likely to occur
This commit is contained in:
parent
ca9fbd8029
commit
d72ad30661
1 changed files with 93 additions and 79 deletions
|
|
@ -1,10 +1,10 @@
|
|||
#!/usr/local/bin/ruby -w
|
||||
|
||||
# $Dwarf: ripnews.rb,v 1.78 2003/09/23 14:43:26 ward Exp $
|
||||
# $Dwarf: ripnews.rb,v 1.79 2004/03/03 21:18:50 ward Exp $
|
||||
# $Source$
|
||||
|
||||
#
|
||||
# Copyright (c) 2002, 2003 Ward Wouts <ward@wouts.nl>
|
||||
# Copyright (c) 2002, 2003, 2004 Ward Wouts <ward@wouts.nl>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software for any
|
||||
# purpose with or without fee is hereby granted, provided that the above
|
||||
|
|
@ -33,6 +33,7 @@ require 'encode/yenc'
|
|||
###########################################################################
|
||||
|
||||
Debuglevel = 0
|
||||
@tstart = Time.now
|
||||
|
||||
def save_file(dir, name, data)
|
||||
print "savename: #{name}\n" if Debuglevel > 1
|
||||
|
|
@ -460,13 +461,20 @@ def get_max_file_length(tempdir=".")
|
|||
print "Tempdir '#{tempdir}' is not a writable directory\n"
|
||||
exit
|
||||
end
|
||||
# this is quite stupid, there is no guarantee at all the generated file names
|
||||
# don't already exist
|
||||
name = "a"*500
|
||||
name = "#$$#{name}"
|
||||
begin
|
||||
file = File.new("#{tempdir}/#{name}", "w", "0644").close
|
||||
File.delete("#{tempdir}/#{name}")
|
||||
rescue Errno::ENAMETOOLONG
|
||||
name = name[0...-1]
|
||||
retry
|
||||
rescue Errno::ENOENT
|
||||
print "#{$!}\n"
|
||||
print "raar hoor\n"
|
||||
retry
|
||||
end
|
||||
# this is how many characters are still likely to be appended
|
||||
# is the filename already exists '-<#{date}.#{count}>' in save_file
|
||||
|
|
@ -491,94 +499,100 @@ def ward_sort(a, b)
|
|||
return 0
|
||||
end
|
||||
|
||||
def startup
|
||||
$stdout.sync=true # line buffered output
|
||||
@defaults = {'-c' => "#{ENV['HOME']}/.ripnewsrc"}
|
||||
@defaults = parse_options(@defaults)
|
||||
@config = parse_config(@defaults)
|
||||
exit if @config == false
|
||||
check_config
|
||||
lock
|
||||
renice
|
||||
|
||||
#############################################################################################
|
||||
|
||||
$stdout.sync=true # line buffered output
|
||||
@defaults = {'-c' => "#{ENV['HOME']}/.ripnewsrc"}
|
||||
@defaults = parse_options(@defaults)
|
||||
@config = parse_config(@defaults)
|
||||
exit if @config == false
|
||||
check_config
|
||||
lock
|
||||
renice
|
||||
|
||||
trap("HUP") {
|
||||
print "Rereading config...\n"
|
||||
config = parse_config(@defaults)
|
||||
if config != false
|
||||
@config = config
|
||||
check_config
|
||||
print "Done reading config\n"
|
||||
else
|
||||
print "Keeping old config due to errors\n"
|
||||
end
|
||||
}
|
||||
|
||||
@maxfilelength = get_max_file_length(@config[@config.keys[0]]["TEMPDIR"])
|
||||
|
||||
print "\n$Id$\n"
|
||||
tstart = Time.now
|
||||
print "Starting: #{tstart}\n"
|
||||
|
||||
if Debuglevel > 2
|
||||
@config.each_key{|i|
|
||||
print "Group: #{i}\n"
|
||||
@config[i].each_key{|j|
|
||||
print "Opt: #{j} val: #{@config[i][j]}\n"
|
||||
}
|
||||
trap("HUP") {
|
||||
print "Rereading config...\n"
|
||||
config = parse_config(@defaults)
|
||||
if config != false
|
||||
@config = config
|
||||
check_config
|
||||
print "Done reading config\n"
|
||||
else
|
||||
print "Keeping old config due to errors\n"
|
||||
end
|
||||
}
|
||||
|
||||
@maxfilelength = get_max_file_length(@config[@config.keys[0]]["TEMPDIR"])
|
||||
|
||||
print "\n$Id$\n"
|
||||
print "Starting: #{@tstart}\n"
|
||||
|
||||
if Debuglevel > 2
|
||||
@config.each_key{|i|
|
||||
print "Group: #{i}\n"
|
||||
@config[i].each_key{|j|
|
||||
print "Opt: #{j} val: #{@config[i][j]}\n"
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
for group in @config.keys.sort
|
||||
print "\nGetting articles for #{group}\n"
|
||||
@articles = Article.new(@config[group]["NNTPSERVER"], group, @config[group]["NEWSRCNAME"])
|
||||
@articles.get_articles(@config[group]["CACHEDIR"])
|
||||
def main
|
||||
for group in @config.keys.sort
|
||||
print "\nGetting articles for #{group}\n"
|
||||
@articles = Article.new(@config[group]["NNTPSERVER"], group, @config[group]["NEWSRCNAME"])
|
||||
@articles.get_articles(@config[group]["CACHEDIR"])
|
||||
|
||||
unless FileTest.directory?("#{@config[group]["DATADIR"]}/#{group}") or
|
||||
Dir.mkdir("#{@config[group]["DATADIR"]}/#{group}", @config[group]["PERMISSION"].oct)
|
||||
print "eeeps, couldn't create dir\n"
|
||||
exit
|
||||
end
|
||||
for i in @articles.get_group_subjects.sort{|a, b| ward_sort(a, b)}
|
||||
print "#{i}\n" if Debuglevel > 2
|
||||
if @config[group].has_key?("-MR") and i =~ /#{@config[group]["-MR"]}/
|
||||
print "Marking '#{i}' as read\n"
|
||||
@articles.group_update_newsrc(i)
|
||||
next
|
||||
unless FileTest.directory?("#{@config[group]["DATADIR"]}/#{group}") or
|
||||
Dir.mkdir("#{@config[group]["DATADIR"]}/#{group}", @config[group]["PERMISSION"].oct)
|
||||
print "eeeps, couldn't create dir\n"
|
||||
exit
|
||||
end
|
||||
if !(@config[group].has_key?("-X") and i =~ /#{@config[group]["-X"]}/) and
|
||||
i =~ /#{@config[group]["-I"]}/
|
||||
print "Match: #{i}\n" if Debuglevel > 0
|
||||
if @articles.group_is_complete(i)
|
||||
begin
|
||||
if @articles.group_is_singlepart(i)
|
||||
succes = get_single(i, group)
|
||||
elsif @articles.group_is_multipart(i)
|
||||
succes = get_multi(i, group)
|
||||
end
|
||||
if succes == false
|
||||
for i in @articles.get_group_subjects.sort{|a, b| ward_sort(a, b)}
|
||||
print "#{i}\n" if Debuglevel > 2
|
||||
if @config[group].has_key?("-MR") and i =~ /#{@config[group]["-MR"]}/
|
||||
print "Marking '#{i}' as read\n"
|
||||
@articles.group_update_newsrc(i)
|
||||
next
|
||||
end
|
||||
if !(@config[group].has_key?("-X") and i =~ /#{@config[group]["-X"]}/) and
|
||||
i =~ /#{@config[group]["-I"]}/
|
||||
print "Match: #{i}\n" if Debuglevel > 0
|
||||
if @articles.group_is_complete(i)
|
||||
begin
|
||||
if @articles.group_is_singlepart(i)
|
||||
succes = get_single(i, group)
|
||||
elsif @articles.group_is_multipart(i)
|
||||
succes = get_multi(i, group)
|
||||
end
|
||||
if succes == false
|
||||
print " Skipping article...\n"
|
||||
end
|
||||
rescue Article::TempError, Article::PermError
|
||||
print "#{$!}\n"
|
||||
print " Skipping article...\n"
|
||||
next
|
||||
end
|
||||
rescue Article::TempError, Article::PermError
|
||||
print "#{$!}\n"
|
||||
print " Skipping article...\n"
|
||||
next
|
||||
else
|
||||
print "Not complete: #{i}\n"
|
||||
end
|
||||
else
|
||||
print "Not complete: #{i}\n"
|
||||
end
|
||||
end
|
||||
@articles.quit
|
||||
end
|
||||
@articles.quit
|
||||
end
|
||||
|
||||
tend = Time.now
|
||||
print "\nFinished: #{tend}\n"
|
||||
runtime = (tend - tstart).to_i
|
||||
h=runtime/3600
|
||||
m=runtime%3600
|
||||
s=m%60
|
||||
m=m/60
|
||||
printf("Running time: %02d:%02d:%02d\n", h, m, s)
|
||||
unlock
|
||||
def ending
|
||||
tend = Time.now
|
||||
print "\nFinished: #{tend}\n"
|
||||
runtime = (tend - @tstart).to_i
|
||||
h=runtime/3600
|
||||
m=runtime%3600
|
||||
s=m%60
|
||||
m=m/60
|
||||
printf("Running time: %02d:%02d:%02d\n", h, m, s)
|
||||
unlock
|
||||
end
|
||||
|
||||
startup
|
||||
main
|
||||
ending
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue