Close options file before starting server

On Windows, the options file cannot be deleted while it is still open by
another process. Close the file before starting the server. Do not explicitly
flush the file as closing implies flushing.
This commit is contained in:
micbou 2017-09-23 02:38:29 +02:00
parent 712c417529
commit ee25d5b8eb
No known key found for this signature in database
GPG Key ID: C7E8FD1F3BDA1E05

View File

@ -138,17 +138,18 @@ class YouCompleteMe( object ):
self._filetypes_with_keywords_loaded = set()
self._server_is_ready_with_cache = False
server_port = utils.GetUnusedLocalhostPort()
# The temp options file is deleted by ycmd during startup
with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file:
hmac_secret = os.urandom( HMAC_SECRET_LENGTH )
options_dict = dict( self._user_options )
options_dict[ 'hmac_secret' ] = utils.ToUnicode(
base64.b64encode( hmac_secret ) )
options_dict[ 'server_keep_logfiles' ] = self._user_options[
'keep_logfiles' ]
# The temp options file is deleted by ycmd during startup.
with NamedTemporaryFile( delete = False, mode = 'w+' ) as options_file:
json.dump( options_dict, options_file )
options_file.flush()
server_port = utils.GetUnusedLocalhostPort()
BaseRequest.server_location = 'http://127.0.0.1:' + str( server_port )
BaseRequest.hmac_secret = hmac_secret