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
|
#!/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$
|
# $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
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
# purpose with or without fee is hereby granted, provided that the above
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
|
@ -33,6 +33,7 @@ require 'encode/yenc'
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
|
||||||
Debuglevel = 0
|
Debuglevel = 0
|
||||||
|
@tstart = Time.now
|
||||||
|
|
||||||
def save_file(dir, name, data)
|
def save_file(dir, name, data)
|
||||||
print "savename: #{name}\n" if Debuglevel > 1
|
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"
|
print "Tempdir '#{tempdir}' is not a writable directory\n"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
# this is quite stupid, there is no guarantee at all the generated file names
|
||||||
|
# don't already exist
|
||||||
name = "a"*500
|
name = "a"*500
|
||||||
|
name = "#$$#{name}"
|
||||||
begin
|
begin
|
||||||
file = File.new("#{tempdir}/#{name}", "w", "0644").close
|
file = File.new("#{tempdir}/#{name}", "w", "0644").close
|
||||||
File.delete("#{tempdir}/#{name}")
|
File.delete("#{tempdir}/#{name}")
|
||||||
rescue Errno::ENAMETOOLONG
|
rescue Errno::ENAMETOOLONG
|
||||||
name = name[0...-1]
|
name = name[0...-1]
|
||||||
retry
|
retry
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
print "#{$!}\n"
|
||||||
|
print "raar hoor\n"
|
||||||
|
retry
|
||||||
end
|
end
|
||||||
# this is how many characters are still likely to be appended
|
# this is how many characters are still likely to be appended
|
||||||
# is the filename already exists '-<#{date}.#{count}>' in save_file
|
# is the filename already exists '-<#{date}.#{count}>' in save_file
|
||||||
|
|
@ -491,19 +499,17 @@ def ward_sort(a, b)
|
||||||
return 0
|
return 0
|
||||||
end
|
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
|
||||||
|
|
||||||
#############################################################################################
|
trap("HUP") {
|
||||||
|
|
||||||
$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"
|
print "Rereading config...\n"
|
||||||
config = parse_config(@defaults)
|
config = parse_config(@defaults)
|
||||||
if config != false
|
if config != false
|
||||||
|
|
@ -513,24 +519,25 @@ trap("HUP") {
|
||||||
else
|
else
|
||||||
print "Keeping old config due to errors\n"
|
print "Keeping old config due to errors\n"
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@maxfilelength = get_max_file_length(@config[@config.keys[0]]["TEMPDIR"])
|
@maxfilelength = get_max_file_length(@config[@config.keys[0]]["TEMPDIR"])
|
||||||
|
|
||||||
print "\n$Id$\n"
|
print "\n$Id$\n"
|
||||||
tstart = Time.now
|
print "Starting: #{@tstart}\n"
|
||||||
print "Starting: #{tstart}\n"
|
|
||||||
|
|
||||||
if Debuglevel > 2
|
if Debuglevel > 2
|
||||||
@config.each_key{|i|
|
@config.each_key{|i|
|
||||||
print "Group: #{i}\n"
|
print "Group: #{i}\n"
|
||||||
@config[i].each_key{|j|
|
@config[i].each_key{|j|
|
||||||
print "Opt: #{j} val: #{@config[i][j]}\n"
|
print "Opt: #{j} val: #{@config[i][j]}\n"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for group in @config.keys.sort
|
def main
|
||||||
|
for group in @config.keys.sort
|
||||||
print "\nGetting articles for #{group}\n"
|
print "\nGetting articles for #{group}\n"
|
||||||
@articles = Article.new(@config[group]["NNTPSERVER"], group, @config[group]["NEWSRCNAME"])
|
@articles = Article.new(@config[group]["NNTPSERVER"], group, @config[group]["NEWSRCNAME"])
|
||||||
@articles.get_articles(@config[group]["CACHEDIR"])
|
@articles.get_articles(@config[group]["CACHEDIR"])
|
||||||
|
|
@ -571,14 +578,21 @@ for group in @config.keys.sort
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@articles.quit
|
@articles.quit
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tend = Time.now
|
def ending
|
||||||
print "\nFinished: #{tend}\n"
|
tend = Time.now
|
||||||
runtime = (tend - tstart).to_i
|
print "\nFinished: #{tend}\n"
|
||||||
h=runtime/3600
|
runtime = (tend - @tstart).to_i
|
||||||
m=runtime%3600
|
h=runtime/3600
|
||||||
s=m%60
|
m=runtime%3600
|
||||||
m=m/60
|
s=m%60
|
||||||
printf("Running time: %02d:%02d:%02d\n", h, m, s)
|
m=m/60
|
||||||
unlock
|
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