]> git.cworth.org Git - sup/commitdiff
bugfix: sup-sync-back without arguments
authorwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Wed, 4 Jul 2007 04:02:25 +0000 (04:02 +0000)
committerwmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Wed, 4 Jul 2007 04:02:25 +0000 (04:02 +0000)
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@471 5c8cc53c-5e98-4d25-b20a-d8db53a31250

bin/sup-sync-back
lib/sup/mbox/loader.rb
lib/sup/sent.rb
lib/sup/source.rb

index 60c8c1b70f2940bf2f99f2b2d5e8abd6a83db10d..c0d6e79b030381cbca6f8391e4a1c0310480f497 100644 (file)
@@ -60,13 +60,13 @@ begin
     s.is_a?(Redwood::MBox::Loader) or Trollop::die "#{uri} is not an mbox source."
     s
   end
-  sources = index.usual_sources if sources.empty?
+  sources = index.usual_sources.select { |s| s.is_a? Redwood::MBox::Loader } if sources.empty?
 
   any_modified = false
-  sources.each { |s| s.reset! }
   
   sources.each do |source|
     $stderr.puts "Scanning #{source}..."
+    source.reset!
     num_deleted = num_moved = num_scanned = 0
     
     out_fp = Tempfile.new "sup-sync-back-#{source.id}"
@@ -108,11 +108,11 @@ begin
     any_modified = true if num_deleted > 0 || num_moved > 0
     out_fp.close unless opts[:dry_run]
 
-    unless opts[:dry_run]
+    unless opts[:dry_run] || !any_modified
       deleted_fp.flush if deleted_fp
       spam_fp.flush if spam_fp
       out_fp.close
-      FileUtils.mv out_fp.path, URI(source.uri).path
+      FileUtils.mv out_fp.path, source.file_path
     end
   end
 
index 49e97036ef8e328c8b66ae86cd55c47068e6ed97..3105f4a40967f471f4140f2b6fc2de183b0ab15b 100644 (file)
@@ -23,6 +23,8 @@ class Loader < Source
     end
   end
 
+  def file_path; URI(uri).path end
+
   def self.suggest_labels_for path
     ## heuristic: use the filename as a label, unless the file
     ## has a path that probably represents an inbox.
index 1f4392d76cd2a84b2f5057d0b68884c65ddcbdb4..b4a57ec259ecade31aefdd97cb35f1d174076319 100644 (file)
@@ -33,11 +33,13 @@ class SentLoader < MBox::Loader
   yaml_properties :cur_offset
 
   def initialize cur_offset=0
-    filename = Redwood::SENT_FN
-    File.open(filename, "w") { } unless File.exists? filename
-    super "mbox://" + filename, cur_offset, true, true
+    @filename = Redwood::SENT_FN
+    File.open(@filename, "w") { } unless File.exists? @filename
+    super "mbox://" + @filename, cur_offset, true, true
   end
 
+  def file_path; @filename end
+
   def uri; SentManager.source_name; end
   def to_s; SentManager.source_name; end
   def id; SentManager.source_id; end
index bcdc6e4801a41b4979e8e7422d8dae096f7800ab..2724b75ce99a7396bef06051c19f9c7f328a2023 100644 (file)
@@ -71,6 +71,8 @@ class Source
     @dirty = false
   end
 
+  def file_path; nil end
+
   def to_s; @uri.to_s; end
   def seek_to! o; self.cur_offset = o; end
   def reset!; seek_to! start_offset; end