sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 3ba2d5d731d76f16dc5f3003b6e061cf1d60f4a6
parent 3a7ab71ea7e7041dba6abd40da6215ecaba1303b
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date:   Mon,  4 Jun 2007 04:53:32 +0000

add locking to sup-sync-back

git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@433 5c8cc53c-5e98-4d25-b20a-d8db53a31250

Diffstat:
M bin/sup-sync-back | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/bin/sup-sync-back b/bin/sup-sync-back
@@ -44,21 +44,24 @@ end
 
 Redwood::start
 index = Redwood::Index.new
-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
-end
+index.lock_or_die
 
+deleted_fp, spam_fp = nil
 unless opts[:dry_run]
   deleted_fp = File.open(opts[:move_deleted], "a") if opts[:move_deleted] 
   spam_fp = File.open(opts[:move_spam], "a") if opts[:move_spam]
 end
 
-any_modified = false
 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
+  end
+
+  any_modified = false
   sources.each { |s| s.reset! }
   
   sources.each do |source|
@@ -123,5 +126,7 @@ rescue Exception => e
   File.open("sup-exception-log.txt", "w") { |f| f.puts e.backtrace }
   raise
 ensure
+  index.save
   Redwood::finish
+  index.unlock
 end