From 1edf22357ff3467fde4a0d5098de6fe44ce59b2c Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Fri, 20 Dec 2013 13:01:48 -0800 Subject: [PATCH] Try to cleanup files only if they stil exist Fixes #738 --- python/ycm/utils.py | 7 +++++++ python/ycm/youcompleteme.py | 24 ++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/python/ycm/utils.py b/python/ycm/utils.py index 124f98fd..92af12f5 100644 --- a/python/ycm/utils.py +++ b/python/ycm/utils.py @@ -79,6 +79,13 @@ def GetUnusedLocalhostPort(): return port +def RemoveIfExists( filename ): + try: + os.remove( filename ) + except OSError: + pass + + def Memoize( obj ): cache = obj.cache = {} diff --git a/python/ycm/youcompleteme.py b/python/ycm/youcompleteme.py index 9c823e81..e7d6caa7 100644 --- a/python/ycm/youcompleteme.py +++ b/python/ycm/youcompleteme.py @@ -141,10 +141,22 @@ class YouCompleteMe( object ): return self._server_popen.pid + def _ServerCleanup( self ): + if self._IsServerAlive(): + self._server_popen.terminate() + utils.RemoveIfExists( self._temp_options_filename ) + + if not self._user_options[ 'server_keep_logfiles' ]: + if self._server_stderr: + utils.RemoveIfExists( self._server_stderr ) + if self._server_stdout: + utils.RemoveIfExists( self._server_stdout ) + + def RestartServer( self ): vimsupport.PostVimMessage( 'Restarting ycmd server...' ) self._user_notified_about_crash = False - self.OnVimLeave() + self._ServerCleanup() self._SetupServer() @@ -237,15 +249,7 @@ class YouCompleteMe( object ): def OnVimLeave( self ): - if self._IsServerAlive(): - self._server_popen.terminate() - os.remove( self._temp_options_filename ) - - if not self._user_options[ 'server_keep_logfiles' ]: - if self._server_stderr: - os.remove( self._server_stderr ) - if self._server_stdout: - os.remove( self._server_stdout ) + self._ServerCleanup() def OnCurrentIdentifierFinished( self ):