@@ -349,18 +349,28 @@ def run(self):
349349 mount_path = mount_sshfs (
350350 self .identifier , typing .cast (PurePath , self .remote_path ), self .mount_path
351351 )
352- if mount_path is None :
353- return
354- add_to_project_folders (
355- str (mount_path ), f"{ ssh_session } { self .remote_path } " , self .view .window ()
356- )
352+ folder_was_in_project = False
353+ is_ok = mount_path is not None
357354 else :
358355 mount_path = typing .cast (Path , self .mount_path )
359- remove_from_project_folders (str (mount_path ), self .view .window ())
360- umount_sshfs (mount_path )
356+ folder_was_in_project = remove_from_project_folders (
357+ str (mount_path ), self .view .window ()
358+ )
359+ is_ok = umount_sshfs (mount_path )
361360 finally :
362361 self .view .erase_status ("zz_mounting_sshfs" )
363362
363+ # in case of mounting success, add folder to project
364+ # in case of unmounting failure, re-add folder to project (if it was present)
365+ if (self .do_mount and is_ok ) or (not self .do_mount and not is_ok and folder_was_in_project ):
366+ add_to_project_folders (
367+ str (mount_path ), f"{ ssh_session } { self .remote_path } " , self .view .window ()
368+ )
369+
370+ # don't update project data if action failed
371+ if not is_ok :
372+ return
373+
364374 # store/remove mount path in/from SSH session metadata
365375 with project_data_lock :
366376 if self .do_mount :
0 commit comments