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