Ensure the renamed file actually exists on disk

Moving a file on Linux can sometimes result in the same path
being returned as the old and new path inside the rename event
because the file watcher doesn't see the new file.

Fixes https://gitlab.com/kicad/code/kicad/issues/5981
This commit is contained in:
Ian McInerney 2020-10-13 16:04:49 +01:00
parent fd874d8345
commit 147d58728f
1 changed files with 5 additions and 2 deletions

View File

@ -1130,10 +1130,13 @@ void TREE_PROJECT_FRAME::OnFileSystemEvent( wxFileSystemWatcherEvent& event )
// Add the new item only if it is not the current project file (root item).
// Remember: this code is called by a wxFileSystemWatcherEvent event, and not always
// called after an actual file rename, and the cleanup code does not explore the
// root item, because it cannot be renamed by the user.
// root item, because it cannot be renamed by the user. Also, ensure the new file actually
// exists on the file system before it is readded. On Linux, moving a file to the trash
// can cause the same path to be returned in both the old and new paths of the event,
// even though the file isn't there anymore.
TREEPROJECT_ITEM* rootData = GetItemIdData( root_id );
if( newfn != rootData->GetFileName() )
if( newpath.Exists() && ( newfn != rootData->GetFileName() ) )
{
wxTreeItemId newroot_id = findSubdirTreeItem( newdir );
wxTreeItemId newitem = AddItemToTreeProject( newfn, newroot_id );