commit a87c26b6fad711c46023613977f4595efd0db277
parent 270959de0b832c86ee0579f39a9111d9b73fbe93
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Wed, 4 Jul 2007 04:02:25 +0000
bugfix: sup-sync-back without arguments
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@471 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
4 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/bin/sup-sync-back b/bin/sup-sync-back
@@ -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
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -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.
diff --git a/lib/sup/sent.rb b/lib/sup/sent.rb
@@ -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
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -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