very basic and unfinished lock file implementation

This commit is contained in:
Ward Wouts 2003-05-24 12:05:57 +00:00
parent 3956313a4c
commit aafbe20872

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w
# $Dwarf: ripnews.rb,v 1.58 2003/04/28 20:28:05 ward Exp $
# $Dwarf: ripnews.rb,v 1.59 2003/04/28 21:52:48 ward Exp $
# $Source$
require 'date'
@ -236,6 +236,24 @@ def check_config
}
end
def lock(group)
if @config[group].has_key?("LOCKFILE")
if FileTest.exists?(@config[group]["LOCKFILE"])
# Should also detect stale locks here
print "Already running, exiting...\n"
exit
else
lock = File.new(@config[group]["LOCKFILE"], "w")
lock.print "#{Process.pid}\n"
lock.close
end
end
end
def unlock(group)
File.unlink(@config[group]["LOCKFILE"])
end
def get_single(subj, group)
print "Fetching singlepart article: #{subj}\n"
body = @articles.get_group_body(subj)
@ -414,6 +432,7 @@ if Debuglevel > 2
end
for group in @config.keys.sort
lock(group)
print "\nGetting articles for #{group}\n"
@articles = Article.new(@config[group]["NNTPSERVER"], group, @config[group]["NEWSRCNAME"])
# begin
@ -462,6 +481,7 @@ for group in @config.keys.sort
end
end
@articles.quit
unlock(group)
end
tend = Time.now