mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-04-04 23:25:30 +00:00
Add a windows specific hack to make backups work past max length
Since backups are most likely to encounter max path limitations compared to other things we do in kicad
This commit is contained in:
parent
870b2ec0c5
commit
0e1b47427c
@ -32,6 +32,7 @@
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <wxstream_helper.h>
|
||||
#include <wx/log.h>
|
||||
#include <kiplatform/io.h>
|
||||
|
||||
#include <set>
|
||||
|
||||
@ -191,7 +192,10 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi
|
||||
wxString msg;
|
||||
wxString oldCwd = wxGetCwd();
|
||||
|
||||
wxSetWorkingDirectory( aSrcDir );
|
||||
wxFileName sourceDir( aSrcDir );
|
||||
KIPLATFORM::IO::LongPathAdjustment( sourceDir );
|
||||
|
||||
wxSetWorkingDirectory( sourceDir.GetFullPath() );
|
||||
|
||||
wxFFileOutputStream ostream( aDestFile );
|
||||
|
||||
@ -210,12 +214,12 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi
|
||||
wxArrayString files;
|
||||
|
||||
for( unsigned ii = 0; ii < arrayDim( extensionList ); ii++ )
|
||||
wxDir::GetAllFiles( aSrcDir, &files, extensionList[ii] );
|
||||
wxDir::GetAllFiles( sourceDir.GetFullPath(), &files, extensionList[ii] );
|
||||
|
||||
if( aIncludeExtraFiles )
|
||||
{
|
||||
for( unsigned ii = 0; ii < arrayDim( extraExtensionList ); ii++ )
|
||||
wxDir::GetAllFiles( aSrcDir, &files, extraExtensionList[ii] );
|
||||
wxDir::GetAllFiles( sourceDir.GetFullPath(), &files, extraExtensionList[ii] );
|
||||
}
|
||||
|
||||
for( unsigned ii = 0; ii < files.GetCount(); ++ii )
|
||||
@ -225,6 +229,7 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi
|
||||
wxFileName package( files[ ii ] );
|
||||
package.MakeRelativeTo( aSrcDir );
|
||||
package.SetExt( wxS( "pkg" ) );
|
||||
KIPLATFORM::IO::LongPathAdjustment( package );
|
||||
|
||||
if( package.Exists() )
|
||||
files.push_back( package.GetFullName() );
|
||||
@ -250,11 +255,13 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi
|
||||
wxFileSystem fsfile;
|
||||
|
||||
wxFileName curr_fn( files[ii] );
|
||||
curr_fn.MakeRelativeTo( aSrcDir );
|
||||
KIPLATFORM::IO::LongPathAdjustment( curr_fn );
|
||||
curr_fn.MakeRelativeTo( sourceDir.GetFullPath() );
|
||||
|
||||
currFilename = curr_fn.GetFullPath();
|
||||
|
||||
// Read input file and add it to the zip file:
|
||||
wxFSFile* infile = fsfile.OpenFile( wxFileSystem::FileNameToURL( curr_fn ) );
|
||||
wxFSFile* infile = fsfile.OpenFile( currFilename );
|
||||
|
||||
if( infile )
|
||||
{
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <dialogs/dialog_migrate_settings.h>
|
||||
#include <gestfich.h>
|
||||
#include <kiplatform/environment.h>
|
||||
#include <kiplatform/io.h>
|
||||
#include <kiway.h>
|
||||
#include <lockfile.h>
|
||||
#include <macros.h>
|
||||
@ -1236,6 +1237,10 @@ bool SETTINGS_MANAGER::BackupProject( REPORTER& aReporter, wxFileName& aTarget )
|
||||
aTarget.SetExt( FILEEXT::ArchiveFileExtension );
|
||||
}
|
||||
|
||||
KIPLATFORM::IO::LongPathAdjustment( aTarget );
|
||||
|
||||
wxString test = aTarget.GetPath();
|
||||
|
||||
if( !aTarget.DirExists() && !wxMkdir( aTarget.GetPath() ) )
|
||||
{
|
||||
wxLogTrace( traceSettings, wxT( "Could not create project backup path %s" ),
|
||||
|
@ -137,10 +137,22 @@ void KIPLATFORM::IO::LongPathAdjustment( wxFileName& aFilename )
|
||||
aFilename.SetVolume( "\\\\?\\" + aFilename.GetVolume() + ":" );
|
||||
else if( aFilename.GetVolume().Length() > 1
|
||||
&& aFilename.GetVolume().StartsWith( wxT( "\\\\" ) )
|
||||
&& !aFilename.GetVolume().StartsWith( wxT( "\\\\?\\" ) ) )
|
||||
&& !aFilename.GetVolume().StartsWith( wxT( "\\\\?" ) ) )
|
||||
// unc path aka network share, wx returns with \\ already
|
||||
// so skip the first slash and combine with the prefix
|
||||
// which in the case of UNCs is actually \\?\UNC\<server>\<share>
|
||||
// where UNC is literally the text UNC
|
||||
aFilename.SetVolume( "\\\\?\\UNC" + aFilename.GetVolume().Mid(1) );
|
||||
aFilename.SetVolume( "\\\\?\\UNC" + aFilename.GetVolume().Mid( 1 ) );
|
||||
else if( aFilename.GetVolume().StartsWith( wxT( "\\\\?" ) )
|
||||
&& aFilename.GetDirs().size() >= 2
|
||||
&& aFilename.GetDirs()[0] == "UNC" )
|
||||
{
|
||||
// wxWidgets can parse \\?\UNC\<server> into a mess
|
||||
// UNC gets stored into a directory
|
||||
// volume gets reduced to just \\?
|
||||
// so we need to repair it
|
||||
aFilename.SetVolume( "\\\\?\\UNC\\" + aFilename.GetDirs()[1] );
|
||||
aFilename.RemoveDir( 0 );
|
||||
aFilename.RemoveDir( 0 );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user