nieuwe groups werden niet gesaved

This commit is contained in:
Ward Wouts 2008-02-24 18:20:07 +00:00
parent e7f301c90d
commit 64d3e59cbb

View file

@ -139,15 +139,15 @@ end
# If not, mutexes are needed.
def save_group_as(file, group)
# @@save_lock.synchronize{
p Time.now
p "copy file"
#p Time.now
#p "copy file"
if FileTest.exists?("#{file}")
if ( ! File.copy(file, "#{file}.bak") )
puts "Can't copy #{file} to #{file}.bak: #{$!}"
end
end
p Time.now
p "open & lock file"
#p Time.now
#p "open & lock file"
begin
newsrc = File.new(file, "r+")
newsrc.flock(File::LOCK_EX)
@ -155,8 +155,8 @@ p "open & lock file"
puts "Can't open ${file}: #{$!}"
exit
end
p Time.now
p "opened & locked"
#p Time.now
#p "opened & locked"
# read file
lines = newsrc.readlines
@ -164,6 +164,7 @@ p "opened & locked"
# pointer -> 0
newsrc.rewind
group_saved = false
# write read stuff & replace group
lines.each{|line|
# same parsing as the parse method uses
@ -179,13 +180,17 @@ p "opened & locked"
linegroup = $1
if linegroup == group["name"]
newsrc.print format(group)
group_saved = true
else
newsrc.print line
end
}
if ! group_saved
newsrc.print format(group)
end
p Time.now
p "truncate, sync, unlock & close file"
#p Time.now
#p "truncate, sync, unlock & close file"
# sometimes the file grows and then shrinks
# this is because a 'read' line van become shorter when more
# articles have been read (1,3,5 vs 1-5)
@ -195,9 +200,9 @@ p "truncate, sync, unlock & close file"
newsrc.sync
newsrc.flock(File::LOCK_UN) # what's the right order here?
newsrc.close
p Time.now
p "garbage collect"
p Time.now
#p Time.now
#p "garbage collect"
#p Time.now
GC.start
# }
end