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