From aafbe20872086fcf0d346a89532315c080aca490 Mon Sep 17 00:00:00 2001 From: Ward Wouts Date: Sat, 24 May 2003 12:05:57 +0000 Subject: [PATCH] very basic and unfinished lock file implementation --- trunk/ripnews/ripnews.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/trunk/ripnews/ripnews.rb b/trunk/ripnews/ripnews.rb index 0d80204..f128a94 100755 --- a/trunk/ripnews/ripnews.rb +++ b/trunk/ripnews/ripnews.rb @@ -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