Apply cloud sync buffer fix to all zip archive outputs
Move CLOUD_SYNC_BUFFER_SIZE constant to kiplatform/io.h header so it can be shared across all archive output locations. Apply the setvbuf fix to additional locations that create zip archives. This is a follow-up to 904b560668 which only fixed project_archiver. Fixes https://gitlab.com/kicad/code/kicad/-/issues/21356
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include <gestfich.h>
|
||||
#include <common.h>
|
||||
#include <wildcards_and_files_ext.h>
|
||||
#include <kiplatform/io.h>
|
||||
|
||||
JOBS_OUTPUT_ARCHIVE::JOBS_OUTPUT_ARCHIVE() :
|
||||
JOBS_OUTPUT_HANDLER(),
|
||||
@@ -61,14 +62,17 @@ bool JOBS_OUTPUT_ARCHIVE::HandleOutputs( const wxString& baseTemp
|
||||
|
||||
wxFFileOutputStream ostream( outputPath );
|
||||
|
||||
if( !ostream.IsOk() ) // issue to create the file. Perhaps not writable dir
|
||||
if( !ostream.IsOk() )
|
||||
{
|
||||
//msg.Printf( _( "Failed to create file '%s'." ), aDestFile );
|
||||
//aReporter.Report( msg, RPT_SEVERITY_ERROR );
|
||||
aResolvedOutputPath.reset();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use a large I/O buffer to improve compatibility with cloud-synced folders.
|
||||
// See KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE comment for details.
|
||||
if( FILE* fp = ostream.GetFile()->fp() )
|
||||
setvbuf( fp, nullptr, _IOFBF, KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE );
|
||||
|
||||
wxZipOutputStream zipstream( ostream, -1, wxConvUTF8 );
|
||||
wxString errors;
|
||||
|
||||
|
||||
@@ -252,6 +252,10 @@ bool PROJECT_ARCHIVER::Archive( const wxString& aSrcDir, const wxString& aDestFi
|
||||
return false;
|
||||
}
|
||||
|
||||
// Use a large I/O buffer to improve compatibility with cloud-synced folders.
|
||||
if( FILE* fp = ostream.GetFile()->fp() )
|
||||
setvbuf( fp, nullptr, _IOFBF, KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE );
|
||||
|
||||
wxZipOutputStream zipstream( ostream, -1, wxConvUTF8 );
|
||||
|
||||
wxDir projectDir( aSrcDir );
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define KIPLATFORM_IO_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <cstddef>
|
||||
|
||||
class wxString;
|
||||
class wxFileName;
|
||||
@@ -29,6 +30,15 @@ namespace KIPLATFORM
|
||||
{
|
||||
namespace IO
|
||||
{
|
||||
/**
|
||||
* Buffer size for file I/O operations on cloud-synced folders.
|
||||
*
|
||||
* Cloud sync services like Google Drive, OneDrive, and Dropbox can report stale file sizes
|
||||
* during seek operations immediately after writing. Using a 512KB buffer reduces the number
|
||||
* of I/O operations and allows the cloud sync driver to flush data more reliably before
|
||||
* subsequent reads. This value was determined empirically to eliminate sync issues.
|
||||
*/
|
||||
static constexpr size_t CLOUD_SYNC_BUFFER_SIZE = 512 * 1024;
|
||||
/**
|
||||
* Opens the file like fopen but sets flags (if available) for sequential read hinting.
|
||||
* Only use this variant of fopen if the file is truely going to be read sequentially only
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
#include <io/io_mgr.h>
|
||||
#include <jobs/job_export_pcb_odb.h>
|
||||
#include <pcb_io/pcb_io_mgr.h>
|
||||
#include <kiplatform/io.h>
|
||||
|
||||
|
||||
|
||||
@@ -462,6 +463,12 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
aProgressReporter->AdvancePhase( _( "Compressing output" ) );
|
||||
|
||||
wxFFileOutputStream fnout( outputFn.GetFullPath() );
|
||||
|
||||
// Use a large I/O buffer to improve compatibility with cloud-synced folders.
|
||||
// See KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE comment for details.
|
||||
if( FILE* fp = fnout.GetFile()->fp() )
|
||||
setvbuf( fp, nullptr, _IOFBF, KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE );
|
||||
|
||||
wxZipOutputStream zipStream( fnout );
|
||||
|
||||
std::function<void( const wxString&, const wxString& )> addDirToZip =
|
||||
@@ -505,6 +512,12 @@ void DIALOG_EXPORT_ODBPP::GenerateODBPPFiles( const JOB_EXPORT_PCB_ODB& aJob, BO
|
||||
else if( aJob.m_compressionMode == JOB_EXPORT_PCB_ODB::ODB_COMPRESSION::TGZ )
|
||||
{
|
||||
wxFFileOutputStream fnout( outputFn.GetFullPath() );
|
||||
|
||||
// Use a large I/O buffer to improve compatibility with cloud-synced folders.
|
||||
// See KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE comment for details.
|
||||
if( FILE* fp = fnout.GetFile()->fp() )
|
||||
setvbuf( fp, nullptr, _IOFBF, KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE );
|
||||
|
||||
wxZlibOutputStream zlibStream( fnout, -1, wxZLIB_GZIP );
|
||||
wxTarOutputStream tarStream( zlibStream );
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/zipstrm.h>
|
||||
#include <wx/filename.h>
|
||||
#include <kiplatform/io.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <dialogs/dialog_gendrill.h>
|
||||
#include <dialogs/dialog_gen_footprint_position.h>
|
||||
@@ -2509,6 +2510,12 @@ int PCBNEW_JOBS_HANDLER::JobExportIpc2581( JOB* aJob )
|
||||
|
||||
{
|
||||
wxFFileOutputStream fnout( zipfn.GetFullPath() );
|
||||
|
||||
// Use a large I/O buffer to improve compatibility with cloud-synced folders.
|
||||
// See KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE comment for details.
|
||||
if( FILE* fp = fnout.GetFile()->fp() )
|
||||
setvbuf( fp, nullptr, _IOFBF, KIPLATFORM::IO::CLOUD_SYNC_BUFFER_SIZE );
|
||||
|
||||
wxZipOutputStream zip( fnout );
|
||||
wxFFileInputStream fnin( tempFile );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user