]> git.cworth.org Git - sup/commitdiff
add locking to sup-sync-back
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 4 Jun 2007 04:53:32 +0000 (04:53 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Mon, 4 Jun 2007 04:53:32 +0000 (04:53 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@433 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup-sync-back

index 46977e08531fff78eb8866d7408c391b9d92f256..871af880216fcb55802aceb80bda7e616913fc07 100644 (file)
@@ -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