Handling os.getcwd() throwing an exception.
This can happen if the CWD has been deleted. Fixes #1129
This commit is contained in:
parent
66898f539e
commit
32e3494d6e
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
import vim
|
import vim
|
||||||
import os
|
import os
|
||||||
|
import tempfile
|
||||||
import json
|
import json
|
||||||
from ycmd.utils import ToUtf8IfNeeded
|
from ycmd.utils import ToUtf8IfNeeded
|
||||||
from ycmd import user_options_store
|
from ycmd import user_options_store
|
||||||
@ -123,8 +124,13 @@ def GetBufferFilepath( buffer_object ):
|
|||||||
if buffer_object.name:
|
if buffer_object.name:
|
||||||
return buffer_object.name
|
return buffer_object.name
|
||||||
# Buffers that have just been created by a command like :enew don't have any
|
# Buffers that have just been created by a command like :enew don't have any
|
||||||
# buffer name so we use the buffer number for that.
|
# buffer name so we use the buffer number for that. Also, os.getcwd() throws
|
||||||
return os.path.join( os.getcwd(), str( buffer_object.number ) )
|
# an exception when the CWD has been deleted so we handle that.
|
||||||
|
try:
|
||||||
|
folder_path = os.getcwd()
|
||||||
|
except OSError:
|
||||||
|
folder_path = tempfile.gettempdir()
|
||||||
|
return os.path.join( folder_path, str( buffer_object.number ) )
|
||||||
|
|
||||||
|
|
||||||
# NOTE: This unplaces *all* signs in a buffer, not just the ones we placed. We
|
# NOTE: This unplaces *all* signs in a buffer, not just the ones we placed. We
|
||||||
|
@ -353,7 +353,11 @@ class YouCompleteMe( object ):
|
|||||||
def _AddTagsFilesIfNeeded( self, extra_data ):
|
def _AddTagsFilesIfNeeded( self, extra_data ):
|
||||||
def GetTagFiles():
|
def GetTagFiles():
|
||||||
tag_files = vim.eval( 'tagfiles()' )
|
tag_files = vim.eval( 'tagfiles()' )
|
||||||
|
# getcwd() throws an exception when the CWD has been deleted.
|
||||||
|
try:
|
||||||
current_working_directory = os.getcwd()
|
current_working_directory = os.getcwd()
|
||||||
|
except OSError:
|
||||||
|
return []
|
||||||
return [ os.path.join( current_working_directory, x ) for x in tag_files ]
|
return [ os.path.join( current_working_directory, x ) for x in tag_files ]
|
||||||
|
|
||||||
if not self._user_options[ 'collect_identifiers_from_tags_files' ]:
|
if not self._user_options[ 'collect_identifiers_from_tags_files' ]:
|
||||||
|
Loading…
Reference in New Issue
Block a user