From cd96f4c55d8457feaf99f786c649c9dd0a6d9f12 Mon Sep 17 00:00:00 2001 From: wmorgan Date: Thu, 30 Aug 2007 23:14:22 +0000 Subject: [PATCH] lock mbox files with dotlockfile in sup-sync-back git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@554 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- bin/sup-sync-back | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/bin/sup-sync-back b/bin/sup-sync-back index 95819b6..61a6baf 100644 --- a/bin/sup-sync-back +++ b/bin/sup-sync-back @@ -10,6 +10,10 @@ require "sup" def save m, fp m.source.each_raw_full_message_line(m.source_info) { |l| fp.print l } end +def die msg + $stderr.puts "Error: #{msg}" + exit(-1) +end opts = Trollop::options do version "sup-sync-back (sup #{Redwood::VERSION})" @@ -34,6 +38,10 @@ EOS opt :move_deleted, "Move deleted messages to a local mbox file.", :type => String, :short => :none opt :drop_spam, "Drop spam messages.", :default => false, :short => "s" opt :move_spam, "Move spam messages to a local mbox file.", :type => String, :short => :none + + opt :with_dotlockfile, "Specific dotlockfile location (mbox files only).", :default => "/usr/bin/dotlockfile", :short => :none + opt :dont_use_dotlockfile, "Don't use dotlockfile to lock mbox files. Dangerous if other processes modify them concurrently.", :default => false, :short => :none + opt :verbose, "Print message ids as they're processed." opt :dry_run, "Don't actually modify the index. Probably only useful with --verbose.", :short => "-n" opt :version, "Show version information", :short => :none @@ -57,12 +65,14 @@ unless opts[:dry_run] spam_fp = File.open(opts[:move_spam], "a") if opts[:move_spam] end +dotlockfile = opts[:with_dotlockfile] || "/usr/bin/dotlockfile" + begin index.load sources = ARGV.map do |uri| - s = index.source_for(uri) or Trollop::die "Unknown source: #{uri}. Did you add it with sup-add first?" - s.is_a?(Redwood::MBox::Loader) or Trollop::die "#{uri} is not an mbox source." + s = index.source_for(uri) or die "unknown source: #{uri}. Did you add it with sup-add first?" + s.is_a?(Redwood::MBox::Loader) or die "#{uri} is not an mbox source." s end @@ -70,6 +80,14 @@ begin sources = index.usual_sources.select { |s| s.is_a? Redwood::MBox::Loader } end + unless sources.all? { |s| s.file_path.nil? } || File.executable?(dotlockfile) || opts[:dont_use_dotlockfile] + die <