Don't copy lock files during project Save As.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15207
This commit is contained in:
Jeff Young 2023-07-16 15:02:12 +01:00
parent ab55684f0b
commit 7b81e964ab
4 changed files with 19 additions and 12 deletions

View File

@ -123,6 +123,8 @@ wxString AddFileExtListToFilter( const std::vector<std::string>& aExts )
} }
const std::string BackupFileSuffix( "-bak" ); const std::string BackupFileSuffix( "-bak" );
const std::string LockFilePrefix( "~" );
const std::string LockFileExtension( "lck" );
const std::string KiCadSymbolLibFileExtension( "kicad_sym" ); const std::string KiCadSymbolLibFileExtension( "kicad_sym" );
const std::string SchematicSymbolFileExtension( "sym" ); const std::string SchematicSymbolFileExtension( "sym" );

View File

@ -35,6 +35,7 @@
#include <wx/log.h> #include <wx/log.h>
#include <wx/filename.h> #include <wx/filename.h>
#include <nlohmann/json.hpp> #include <nlohmann/json.hpp>
#include <wildcards_and_files_ext.h>
#define LCK "KICAD_LOCKING" #define LCK "KICAD_LOCKING"
@ -50,8 +51,8 @@ public:
wxLogTrace( LCK, "Trying to lock %s", filename ); wxLogTrace( LCK, "Trying to lock %s", filename );
wxFileName fn( filename ); wxFileName fn( filename );
fn.SetName( "~" + fn.GetName() ); fn.SetName( LockFilePrefix + fn.GetName() );
fn.SetExt( fn.GetExt() + ".lck" ); fn.SetExt( fn.GetExt() + '.' + LockFileExtension );
if( !fn.IsDirWritable() ) if( !fn.IsDirWritable() )
{ {
@ -193,7 +194,7 @@ public:
catch( std::exception& e ) catch( std::exception& e )
{ {
wxLogError( "Got exception trying to override lock on %s: %s", wxLogError( "Got exception trying to override lock on %s: %s",
m_lockFilename, e.what() ); m_lockFilename, e.what() );
return false; return false;
} }
@ -253,8 +254,7 @@ private:
if( !fileName.FileExists() ) if( !fileName.FileExists() )
{ {
wxLogTrace wxLogTrace( LCK, "File does not exist: %s", m_lockFilename );
( LCK, "File does not exist: %s", m_lockFilename );
return false; return false;
} }
@ -266,24 +266,23 @@ private:
wxString lock_info; wxString lock_info;
file.ReadAll( &lock_info ); file.ReadAll( &lock_info );
nlohmann::json j = nlohmann::json::parse( std::string( lock_info.mb_str() ) ); nlohmann::json j = nlohmann::json::parse( std::string( lock_info.mb_str() ) );
if( m_username == wxString( j["username"].get<std::string>() ) if( m_username == wxString( j["username"].get<std::string>() )
&& m_hostname == wxString( j["hostname"].get<std::string>() ) ) && m_hostname == wxString( j["hostname"].get<std::string>() ) )
{ {
wxLogTrace wxLogTrace( LCK, "User and host match for lock %s", m_lockFilename );
( LCK, "User and host match for lock %s", m_lockFilename );
return true; return true;
} }
} }
} }
catch( std::exception &e ) catch( std::exception &e )
{ {
wxLogError wxLogError( "Got exception trying to check user/host for lock on %s: %s",
( "Got exception trying to check user/host for lock on %s: %s", m_lockFilename, m_lockFilename,
e.what() ); e.what() );
} }
wxLogTrace wxLogTrace( LCK, "User and host DID NOT match for lock %s", m_lockFilename );
( LCK, "User and host DID NOT match for lock %s", m_lockFilename );
return false; return false;
} }
}; };

View File

@ -109,6 +109,8 @@ wxString AddFileExtListToFilter( const std::vector<std::string>& aExts );
wxString formatWildcardExt( const wxString& aWildcard ); wxString formatWildcardExt( const wxString& aWildcard );
extern const std::string BackupFileSuffix; extern const std::string BackupFileSuffix;
extern const std::string LockFilePrefix;
extern const std::string LockFileExtension;
extern const std::string SchematicSymbolFileExtension; extern const std::string SchematicSymbolFileExtension;
extern const std::string LegacySymbolLibFileExtension; extern const std::string LegacySymbolLibFileExtension;

View File

@ -536,6 +536,10 @@ public:
gerbview->SaveFileAs( m_projectDirPath, m_projectName, m_newProjectDirPath, gerbview->SaveFileAs( m_projectDirPath, m_projectName, m_newProjectDirPath,
m_newProjectName, aSrcFilePath, m_errors ); m_newProjectName, aSrcFilePath, m_errors );
} }
else if(destFile.GetName().StartsWith( LockFilePrefix ) && ext == LockFileExtension )
{
// Ignore lock files
}
else else
{ {
// Everything we don't recognize just gets a straight copy. // Everything we don't recognize just gets a straight copy.