Skip to content

Commit

Permalink
Ensure the renamed file actually exists on disk
Browse files Browse the repository at this point in the history
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
  • Loading branch information
imciner2 committed Oct 13, 2020
1 parent fd874d8 commit 147d587
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions kicad/tree_project_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down

0 comments on commit 147d587

Please sign in to comment.