@@ -203,16 +203,18 @@ def delete_project(self, project_dir: Path) -> None:
203203            raise  RuntimeError (f"Failed to delete project. Could not find the specified path { project_dir }  )
204204
205205
206-     def  get_local_project_path (self , project_name : str , cloud_id : Optional [int ] =  None , local_id : Optional [int ] =  None ) ->  Path :
206+     def  get_local_project_path (self , project_name : str , cloud_id : Optional [int ] =  None , local_id : Optional [int ] =  None ,
207+                                allow_corrupted : Optional [bool ] =  False ) ->  Path :
207208        """Returns the local path where a certain cloud project should be stored. 
208209
209210        If two cloud projects are named "Project", they are pulled to ./Project and ./Project 2. 
210211
211212        If you push a project with unsupported cloud name, a supported project name would be assigned. 
212213
213-         :param project_name: the cloud project to get the project path of 
214-         :param cloud_id: the cloud project to get the project path of 
215-         :param local_id: the cloud project to get the project path of 
214+         :param project_name: the cloud project name to get the project path of 
215+         :param cloud_id: the cloud project id to get the project path of 
216+         :param local_id: the cloud project local id to get the project path of 
217+         :param allow_corrupted: true if a corrupted path can be used 
216218        :return: the path to the local project directory 
217219        """ 
218220
@@ -226,6 +228,7 @@ def get_local_project_path(self, project_name: str, cloud_id: Optional[int] = No
226228
227229        current_index  =  1 
228230        while  True :
231+             # we first check the current project name 
229232            path_suffix  =  ""  if  current_index  ==  1  else  f" { current_index }  
230233            current_path  =  Path .cwd () /  (local_path  +  path_suffix )
231234
@@ -234,14 +237,33 @@ def get_local_project_path(self, project_name: str, cloud_id: Optional[int] = No
234237
235238            if  cloud_id  is  not None :
236239                current_project_config  =  self ._project_config_manager .get_project_config (current_path )
237-                 if  current_project_config .get ("cloud-id" ) ==  cloud_id :
240+                 if  current_project_config .is_empty ():
241+                     self ._logger .error (f"'{ current_path } { PROJECT_CONFIG_FILE_NAME }  )
242+                     if  allow_corrupted :
243+                         return  current_path 
244+                 elif  current_project_config .get ("cloud-id" ) ==  cloud_id :
238245                    return  current_path 
239246
240247            if  local_id  is  not None :
241248                current_project_config  =  self ._project_config_manager .get_project_config (current_path )
242-                 if  current_project_config .get ("local-id" ) ==  local_id :
249+                 if  current_project_config .is_empty ():
250+                     self ._logger .error (f"'{ current_path } { PROJECT_CONFIG_FILE_NAME }  )
251+                     if  allow_corrupted :
252+                         return  current_path 
253+                 elif  current_project_config .get ("local-id" ) ==  local_id :
243254                    return  current_path 
244255
256+             if  current_index  ==  1 :
257+                 from  re  import  findall 
258+ 
259+                 ints_in_name  =  findall (r"(\s\d+)$" , local_path )
260+                 if  len (ints_in_name ) !=  0 :
261+                     # the current project name already exists, and it has a 'space + int' at the end of it 
262+                     # so, we take that int and increment it 
263+                     int_value  =  ints_in_name [0 ]
264+                     # we remove the int from the name because we will re add it in the loop 
265+                     local_path  =  local_path [:- len (int_value )]
266+                     current_index  =  int (int_value )
245267            current_index  +=  1 
246268
247269    def  rename_project_and_contents (self , old_path : Path , new_path : Path ,) ->  None :
0 commit comments