From 118ee1c072c4cf0450c577dc8a2c8f8b7a577b2c Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 15 Aug 2025 13:49:32 -0700 Subject: [PATCH] Prevent autosave error from cluttering the screen Once per session, per editor we can show the error. After that, assume that the designer has seen and knows about the issue. Fixes https://gitlab.com/kicad/code/kicad/issues/21464 (cherry picked from commit 9f2b04c7e2294c50fd9a6cbd56daa8267a1ab32b) --- common/eda_base_frame.cpp | 1 + eeschema/files-io.cpp | 26 +++++++++++++++++++++++++- include/eda_base_frame.h | 1 + pcbnew/files.cpp | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index f37560d99e..98478aae94 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -141,6 +141,7 @@ void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType ) m_isNonUserClose = false; m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER ); m_autoSaveRequired = false; + m_autoSavePermissionError = false; m_mruPath = PATHS::GetDefaultUserProjectsPath(); m_frameSize = defaultSize( aFrameType, this ); m_displayIndex = -1; diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 5d63f058fb..8a0bdc065a 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1230,8 +1230,18 @@ bool SCH_EDIT_FRAME::doAutoSave() if( !tmp.IsOk() ) return false; - if( !IsWritable( tmp ) ) + if( !IsWritable( tmp, false ) ) + { + if( !m_autoSavePermissionError ) + { + DisplayError( this, wxString::Format( + _( "Could not autosave files to read-only folder: '%s'" ), + tmp.GetPath() ) ); + m_autoSavePermissionError = true; + } + return false; + } wxString title = GetTitle(); // Save frame title, that can be modified by the save process @@ -1246,6 +1256,20 @@ bool SCH_EDIT_FRAME::doAutoSave() // Auto save file name is the normal file name prefixed with GetAutoSavePrefix(). fn.SetName( FILEEXT::AutoSaveFilePrefix + fn.GetName() ); + if( !IsWritable( fn, false ) ) + { + if( !m_autoSavePermissionError ) + { + DisplayError( this, wxString::Format( + _( "Could not autosave files to read-only folder: '%s'" ), + fn.GetPath() ) ); + m_autoSavePermissionError = true; + } + + autoSaveOk = false; + continue; + } + if( saveSchematicFile( screens.GetSheet( i ), fn.GetFullPath() ) ) { // This was only an auto-save, not a real save. Reset the modified flag. diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index 44d8affc36..65f0608380 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -771,6 +771,7 @@ private: bool m_autoSavePending; bool m_autoSaveRequired; wxTimer* m_autoSaveTimer; + bool m_autoSavePermissionError; int m_undoRedoCountMax; // undo/Redo command Max depth diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 7918354979..52521f3ae1 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -1200,12 +1200,33 @@ bool PCB_EDIT_FRAME::doAutoSave() // path. If that path isn't writable, give up. if( !autoSaveFileName.IsDirWritable() ) { + if( !m_autoSavePermissionError ) + { + DisplayError( this, wxString::Format( + _( "Could not autosave files to read-only folder: '%s'" ), + autoSaveFileName.GetPath() ) ); + m_autoSavePermissionError = true; + } + autoSaveFileName.SetPath( wxFileName::GetTempDir() ); if( !autoSaveFileName.IsOk() || !autoSaveFileName.IsDirWritable() ) return false; } + if( !IsWritable( autoSaveFileName, false ) ) + { + if( !m_autoSavePermissionError ) + { + DisplayError( this, wxString::Format( + _( "Could not autosave files to read-only folder: '%s'" ), + autoSaveFileName.GetPath() ) ); + m_autoSavePermissionError = true; + } + + return false; + } + wxLogTrace( traceAutoSave, wxT( "Creating auto save file <" ) + autoSaveFileName.GetFullPath() + wxT( ">" ) );