sup

A curses threads-with-tags style email client

sup.git

git clone https://supmua.dev/git/sup/
commit 5c546294804c84062082d8c1a4f6311d56c028bb
parent a42dca76b0e1855e869862111c3bccac5095c908
Author: Damien Leone <damien.leone@fensalir.fr>
Date:   Sat, 26 Feb 2011 18:02:49 +0100

Check whether the "sync_back_to_maildir" option has been changed from false to true suggest the user to run sup-sync-back-to-maildir before continuing if needed

The check occurs when starting the Redwood module so it affects every
executables loading it since some of them can modify the index (sup,
sup-sync, etc.).

There is a new parameter called "bypass_sync_check" to the
Redwood::start method to bypass this check, it is useful for scripts
such as sup-sync-back-to-maildir itself!

It works by checking the presence of a flag file in the configuration
directory. The file is written when the synchronization is performed
and deleted when the "sync_back_to_maildir" option is set to false.

Diffstat:
M bin/sup-sync-back-maildir | 5 ++++-
M lib/sup.rb | 29 ++++++++++++++++++++++++++++-
2 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/bin/sup-sync-back-maildir b/bin/sup-sync-back-maildir
@@ -45,7 +45,7 @@ def die msg
   exit(-1)
 end
 
-Redwood::start
+Redwood::start true
 index = Redwood::Index.init
 index.lock_interactively or exit
 index.load
@@ -92,6 +92,9 @@ begin
         end
       end
       print "\n"
+
+      ## Write a flag file to tell sup that the synchronization has been performed
+      File.open(Redwood::SYNC_OK_FN, 'w') {|f| f.write("OK") }
     end
   end
 rescue Exception => e
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -54,6 +54,7 @@ module Redwood
   HOOK_DIR   = File.join(BASE_DIR, "hooks")
   SEARCH_FN  = File.join(BASE_DIR, "searches.txt")
   LOG_FN     = File.join(BASE_DIR, "log")
+  SYNC_OK_FN = File.join(BASE_DIR, "sync-back-ok")
 
   YAML_DOMAIN = "masanjin.net"
   YAML_DATE = "2006-10-01"
@@ -151,7 +152,7 @@ module Redwood
     SourceManager SearchManager IdleManager).map { |x| Redwood.const_get x.to_sym }
   end
 
-  def start
+  def start bypass_sync_check = false
     managers.each { |x| fail "#{x} already instantiated" if x.instantiated? }
 
     FileUtils.mkdir_p Redwood::BASE_DIR
@@ -167,6 +168,32 @@ module Redwood
     Redwood::SearchManager.init Redwood::SEARCH_FN
 
     managers.each { |x| x.init unless x.instantiated? }
+
+    return if bypass_sync_check
+
+    if $config[:sync_back_to_maildir] and not File.exists? Redwood::SYNC_OK_FN
+      $stderr.puts <<EOS
+WARNING
+-------
+
+It appears that the "sync_back_to_maildir" option has been changed
+from false to true since the last execution of sup.
+
+It is *strongly* recommended that you run "sup-sync-back-maildir"
+before continuing, otherwise you might lose informations in your
+Xapian index.
+
+This script should be executed each time the "sync_back_to_maildir" is
+changed from false to true.
+
+Please run "sup-sync-back-maildir -h" to see why it is useful.
+
+Are you really sure you want to continue? (y/N)
+EOS
+      abort "Aborted" unless STDIN.gets.chomp.downcase == 'y'
+    elsif not $config[:sync_back_to_maildir] and File.exists? Redwood::SYNC_OK_FN
+      File.delete(Redwood::SYNC_OK_FN)
+    end
   end
 
   def finish