Просмотр исходного кода

Handling os.getcwd() throwing an exception.

This can happen if the CWD has been deleted.

Fixes #1129
Strahinja Val Markovic 10 лет назад
Родитель
Сommit
32e3494d6e
2 измененных файлов с 13 добавлено и 3 удалено
  1. 8 2
      python/ycm/vimsupport.py
  2. 5 1
      python/ycm/youcompleteme.py

+ 8 - 2
python/ycm/vimsupport.py

@@ -19,6 +19,7 @@
 
 import vim
 import os
+import tempfile
 import json
 from ycmd.utils import ToUtf8IfNeeded
 from ycmd import user_options_store
@@ -123,8 +124,13 @@ def GetBufferFilepath( buffer_object ):
   if buffer_object.name:
     return buffer_object.name
   # 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.
-  return os.path.join( os.getcwd(), str( buffer_object.number ) )
+  # buffer name so we use the buffer number for that. Also, os.getcwd() throws
+  # 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

+ 5 - 1
python/ycm/youcompleteme.py

@@ -353,7 +353,11 @@ class YouCompleteMe( object ):
   def _AddTagsFilesIfNeeded( self, extra_data ):
     def GetTagFiles():
       tag_files = vim.eval( 'tagfiles()' )
-      current_working_directory = os.getcwd()
+      # getcwd() throws an exception when the CWD has been deleted.
+      try:
+        current_working_directory = os.getcwd()
+      except OSError:
+        return []
       return [ os.path.join( current_working_directory, x ) for x in tag_files ]
 
     if not self._user_options[ 'collect_identifiers_from_tags_files' ]: