keep old config when there are errors in the new one when reloading

This commit is contained in:
Ward Wouts 2003-07-13 11:18:09 +00:00
parent 95c43e0619
commit bc42886d52

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w
# $Dwarf: ripnews.rb,v 1.73 2003/06/24 19:35:56 ward Exp $
# $Dwarf: ripnews.rb,v 1.74 2003/07/03 14:30:00 ward Exp $
# $Source$
require 'date'
@ -128,7 +128,7 @@ def parse_config(default = {})
i = 0
group = ""
grouparr = []
@config = {}
config = {}
lines.collect!{|x|
x.sub!(/^\s*/, "")
@ -158,12 +158,12 @@ def parse_config(default = {})
end
else
grouparr.collect{|g|
if @config[g].has_key?($1)
@config[g][$1] << $2
if config[g].has_key?($1)
config[g][$1] << $2
elsif default.has_key?($1)
@config[g][$1] = default[$1] + $2
config[g][$1] = default[$1] + $2
else
@config[g][$1] = $2
config[g][$1] = $2
end
}
end
@ -172,19 +172,19 @@ def parse_config(default = {})
default[$1] = $2
else
grouparr.collect{|g|
@config[g][$1] = $2
config[g][$1] = $2
}
end
elsif line =~ /(.*?)\s*\{/
group = $1
grouparr = group.split('|')
grouparr.collect{|g|
@config[g] = {} unless @config.has_key?(g)
config[g] = {} unless config.has_key?(g)
}
elsif line =~ /^}$/
default.each_key{|x|
grouparr.collect{|g|
@config[g][x] = default[x] unless @config[g].has_key?(x)
config[g][x] = default[x] unless config[g].has_key?(x)
}
}
group = ""
@ -193,24 +193,24 @@ def parse_config(default = {})
next
else
print "Error parsing config on line: #{i}\n"
exit
return false
end
end
if group != ""
print "Error parsing config: group not terminated on line #{i}\n"
exit
return false
end
if Debuglevel > 2
@config.each_key{|x|
config.each_key{|x|
print "Group: #{x}\n"
@config[x].each_key{|y|
print "Key: '#{y}' => Value: '#{@config[x][y]}'\n"
config[x].each_key{|y|
print "Key: '#{y}' => Value: '#{config[x][y]}'\n"
}
}
end
return true
return config
end
def check_config
@ -221,7 +221,6 @@ def check_config
@config.each_key {|i|
unless @config[i].has_key?("-I")
print "No inclusions given for group #{i}. Won't match anything.\n"
exit
end
@config[i]["DATADIR"] ="." unless @config[i].has_key?("DATADIR")
@config[i]["PERMISSION"] = "0755" unless @config[i].has_key?("PERMISSION")
@ -475,16 +474,22 @@ end
$stdout.sync=true # line buffered output
@defaults = {'-c' => "#{ENV['HOME']}/.ripnewsrc"}
@defaults = parse_options(@defaults)
parse_config(@defaults)
@config = parse_config(@defaults)
exit if @config == false
check_config
lock
renice
trap("HUP") {
puts "Rereading config...\n"
parse_config(@defaults)
check_config
puts "Done reading config\n"
config = parse_config(@defaults)
if config != false
@config = config
check_config
puts "Done reading config\n"
else
puts "Keeping old config due to errors\n"
end
}
@maxfilelength = get_max_file_length(@config[@config.keys[0]]["TEMPDIR"])