]> git.cworth.org Git - sup/blobdiff - lib/sup/mbox/ssh-file.rb
Merge branch 'xapian-updates'
[sup] / lib / sup / mbox / ssh-file.rb
index 6e91c2089f96c77b62430077120d0d0c63a6db27..4ae4bbadf6f875b8655dbe5b461bca2b31afef22 100644 (file)
@@ -16,12 +16,6 @@ class SSHFileError < StandardError; end
 ## all of the methods here can throw SSHFileErrors, SocketErrors,
 ## Net::SSH::Exceptions and Errno::ENOENTs.
 
-## debugging TODO: remove me
-def debug s
-  Redwood::log s
-end
-module_function :debug
-
 ## a simple buffer of contiguous data
 class Buffer
   def initialize
@@ -106,14 +100,12 @@ class SSHFile
     @file_size = nil
     @offset = 0
     @say_id = nil
-    @broken_msg = nil
     @shell = nil
     @shell_mutex = nil
     @buf_mutex = Mutex.new
   end
 
   def to_s; "mbox+ssh://#@host/#@fn"; end ## TODO: remove this EVILness
-  def broken?; !@broken_msg.nil?; end
 
   def connect
     do_remote nil
@@ -124,6 +116,7 @@ class SSHFile
   def seek loc; @offset = loc; end
   def tell; @offset; end
   def total; size; end
+  def path; @fn end
 
   def size
     if @file_size.nil? || (Time.now - @last_size_check) > SIZE_CHECK_INTERVAL
@@ -155,7 +148,7 @@ private
   ## TODO: share this code with imap
   def say s
     @say_id = BufferManager.say s, @say_id if BufferManager.instantiated?
-    Redwood::log s
+    info s
   end
 
   def shutup
@@ -164,7 +157,6 @@ private
   end
 
   def unsafe_connect
-    raise SSHFileError, @broken_msg if broken?
     return if @shell
 
     @key = [@host, @ssh_opts[:username]]
@@ -172,14 +164,13 @@ private
       @shell, @shell_mutex = @@shells_mutex.synchronize do
         unless @@shells.member? @key
           say "Opening SSH connection to #{@host} for #@fn..."
-          #raise SSHFileError, "simulated SSH file error"
           session = Net::SSH.start @host, @ssh_opts
           say "Starting SSH shell..."
           @@shells[@key] = [session.shell.sync, Mutex.new]
         end
         @@shells[@key]
       end
-
+      
       say "Checking for #@fn..."
       @shell_mutex.synchronize { raise Errno::ENOENT, @fn unless @shell.test("-e #@fn").status == 0 }
     ensure
@@ -190,29 +181,24 @@ private
   def do_remote cmd, expected_size=0
     retries = 0
     result = nil
-    begin
-      begin
-        unsafe_connect
-        if cmd
-          # MBox::debug "sending command: #{cmd.inspect}"
-          result = @shell_mutex.synchronize { x = @shell.send_command cmd; sleep 0.25; x }
-          raise SSHFileError, "Failure during remote command #{cmd.inspect}: #{(result.stderr || result.stdout || "")[0 .. 100]}" unless result.status == 0
-        end
 
-        ## Net::SSH::Exceptions seem to happen every once in a while for
-        ## no good reason.
-      rescue Net::SSH::Exception, *RECOVERABLE_ERRORS
-        if (retries += 1) <= 3
-          @@shells_mutex.synchronize do
-            @shell = nil
-            @@shells[@key] = nil
-          end
-          retry
+    begin
+      unsafe_connect
+      if cmd
+        # MBox::debug "sending command: #{cmd.inspect}"
+        result = @shell_mutex.synchronize { x = @shell.send_command cmd; sleep 0.25; x }
+        raise SSHFileError, "Failure during remote command #{cmd.inspect}: #{(result.stderr || result.stdout || "")[0 .. 100]}" unless result.status == 0
+      end
+      ## Net::SSH::Exceptions seem to happen every once in a while for
+      ## no good reason.
+    rescue Net::SSH::Exception, *RECOVERABLE_ERRORS
+      if (retries += 1) <= 3
+        @@shells_mutex.synchronize do
+          @shell = nil
+          @@shells[@key] = nil
         end
-        raise
+        retry
       end
-    rescue Net::SSH::Exception, SSHFileError, SystemCallError => e
-      @broken_msg = e.message
       raise
     end