Permalink
Browse files

Fix stale session bugs.

  • Loading branch information...
1 parent 2e2e20e commit 66c9ba4365f704cc67abc7098405acc4368516f9 @Pistos committed Mar 13, 2013
Showing with 46 additions and 31 deletions.
  1. +4 −0 CHANGELOG
  2. +7 −6 lib/diakonos.rb
  3. +35 −25 lib/diakonos/sessions.rb
View
4 CHANGELOG
@@ -1,6 +1,10 @@
Diakonos Changelog
------------------
+0.9.2
+
+- Fixed stale session bugs.
+
0.9.1
- Added PKGBUILD to bash filemask.
View
13 lib/diakonos.rb
@@ -300,12 +300,12 @@ def start
@buffers << Buffer.new( file )
end
if ! @testing
- session_buffers = session_startup
+ session_startup
end
- session_buffer_number = @session[ 'buffer_current' ] || 1
@files.each do |file_info|
@buffers << Buffer.new( file_info )
end
+ @files = []
if @buffers.empty?
@buffers << Buffer.new
end
@@ -341,12 +341,13 @@ def start
hook.sort { |a,b| a[ :priority ] <=> b[ :priority ] }
end
- if session_buffers
- session_buffers.each do |buffer|
- close_buffer buffer
- end
+ handle_stale_session_files
+
+ @files.each do |file_info|
+ @buffers << Buffer.new( file_info )
end
+ session_buffer_number = @session[ 'buffer_current' ] || 1
if ! switch_to_buffer_number( session_buffer_number )
debug_log "Failed to switch to buffer #{session_buffer_number.inspect}"
switch_to_buffer_number 1
View
60 lib/diakonos/sessions.rb
@@ -139,6 +139,8 @@ def session_filepaths
end
def session_startup
+ @stale_session_files = []
+
if @session_to_load
pid_session = @session
@session = nil
@@ -148,7 +150,6 @@ def session_startup
new_session session_path
end
else
- stale_session_files = []
session_files = Dir[ "#{@session_dir}/*" ].grep( %r{/\d+$} )
session_files.each do |sf|
pid = sf[ %r{/(\d+)$}, 1 ].to_i
@@ -158,46 +159,55 @@ def session_startup
Process.kill 0, pid
rescue Errno::ESRCH, Errno::EPERM
if self.pid_session?(sf)
- stale_session_files << sf
+ @stale_session_files << sf
end
end
end
+ end
+ end
- session_buffers = []
- stale_session_files.each_with_index do |session_file,index|
- session_buffers << open_file( session_file )
+ # We have to do this separately and later (as opposed to inside #session_startup)
+ # because we have to wait for the display to get initialized in order to
+ # prompt the user for input, etc.
+ def handle_stale_session_files
+ return if @stale_session_files.empty?
- choice = get_choice(
- "#{stale_session_files.size} unclosed session(s) found. Open the above files? (session #{index+1} of #{stale_session_files.size})",
- [ CHOICE_YES, CHOICE_NO, CHOICE_DELETE ],
- index > 0 ? CHOICE_NO : nil
- )
+ session_buffers = []
+ @stale_session_files.each_with_index do |session_file,index|
+ session_buffers << open_file( session_file )
- case choice
- when CHOICE_YES
- load_session session_file
- if @session
- File.delete session_file
- break
- end
- when CHOICE_DELETE
+ choice = get_choice(
+ "#{@stale_session_files.size} unclosed session(s) found. Open the above files? (session #{index+1} of #{@stale_session_files.size})",
+ [ CHOICE_YES, CHOICE_NO, CHOICE_DELETE ],
+ index > 0 ? CHOICE_NO : nil
+ )
+
+ case choice
+ when CHOICE_YES
+ load_session session_file
+ if @session
File.delete session_file
+ break
end
+ when CHOICE_DELETE
+ File.delete session_file
end
+ end
- if session_buffers.empty? && @files.empty? && @settings[ 'session.default_session' ]
- session_file = session_filepath_for( @settings[ 'session.default_session' ] )
- if File.exist? session_file
- load_session session_file
- end
+ if session_buffers.empty? && @files.empty? && @settings[ 'session.default_session' ]
+ session_file = session_filepath_for( @settings[ 'session.default_session' ] )
+ if File.exist? session_file
+ load_session session_file
end
end
- session_buffers
+ session_buffers.each do |buffer|
+ close_buffer buffer
+ end
end
def cleanup_session
- if self.pid_session? && File.exists?( @session[ 'filename' ] )
+ if @session && self.pid_session? && File.exists?( @session[ 'filename' ] )
File.delete @session[ 'filename' ]
end
end

0 comments on commit 66c9ba4

Please sign in to comment.