← Back to team overview

kicad-developers team mailing list archive

PATCH: Compare project paths at load, not inodes

 

Subtle bug here, only occurs in rare occasions:

Assuming: a project exists in /a/b/project.pro, and /a/b is symlinked to /a/c

1. Load /a/b/project.pro
2. Load /a/c/project.pro

Expectation: filename switches to /a/c/project.pro (even though they are the same file, a user would expect the path to reflect the file selection he just made)

Reality: filename does not switch

This is because PROJECT::SetProjectFullName does not do anything if the path is not changed, and it uses wxFileName::SameAs to check this. For some bizarre reason, wxFileName::SameAs compares filesystem inodes rather than actual paths.

This patch instead creates a second wxFileName from the candidate name in order to normalize the path, and then compares paths directly. IMO this should be much more in line with what a user would expect.

--
Chris
commit 162a80673b0f1e638325ecfe43fbdfeccb2e25a1
Author: Chris Pavlina <cpavlin1@xxxxxxxxxxxxxx>
Date:   Sat Oct 31 12:41:14 2015 -0400

    Compare actual paths at project load, not inodes

diff --git a/common/project.cpp b/common/project.cpp
index ebf8f13..a6b7546 100644
--- a/common/project.cpp
+++ b/common/project.cpp
@@ -63,9 +63,13 @@ PROJECT::~PROJECT()
 
 void PROJECT::SetProjectFullName( const wxString& aFullPathAndName )
 {
+    // Compare paths, rather than inodes, to be less surprising to the user.
+    // Create a temporary wxFileName to normalize the path
+    wxFileName candidate_path( aFullPathAndName );
+
     // Edge transitions only.  This is what clears the project
     // data using the Clear() function.
-    if( m_project_name != aFullPathAndName )
+    if( m_project_name.GetFullPath() != candidate_path.GetFullPath() )
     {
         Clear();            // clear the data when the project changes.
 

Follow ups