Merge pull request #2288 from KLayout/bugfix/issue-2284

Implemented backup files for the configuration file
This commit is contained in:
Matthias Köfferlein
2026-03-01 23:25:08 +01:00
committed by GitHub
7 changed files with 30 additions and 12 deletions
@@ -71,12 +71,17 @@ Class<lay::Dispatcher> decl_Dispatcher ("lay", "Dispatcher",
"\n"
"@return The instance\n"
) +
method ("write_config", &lay::Dispatcher::write_config, gsi::arg ("file_name"),
method ("write_config", &lay::Dispatcher::write_config, gsi::arg ("file_name"), gsi::arg ("keep_backups", 0),
"@brief Writes configuration to a file\n"
"@return A value indicating whether the operation was successful\n"
"\n"
"If the configuration file cannot be written, false \n"
"is returned but no exception is thrown.\n"
"\n"
"@param file_name The path to write the config file to.\n"
"@param keep_backups The number of backups to keep (0 for 'no backups').\n"
"\n"
"The 'keep_backups' option was introduced in version 0.30.7.\n"
) +
method ("read_config", &lay::Dispatcher::read_config, gsi::arg ("file_name"),
"@brief Reads the configuration from a file\n"
+2 -2
View File
@@ -238,10 +238,10 @@ config_structure (const lay::Dispatcher *plugin)
bool
Dispatcher::write_config (const std::string &config_file)
Dispatcher::write_config (const std::string &config_file, int keep_backups)
{
try {
tl::OutputStream os (config_file, tl::OutputStream::OM_Plain);
tl::OutputStream os (config_file, tl::OutputStream::OM_Plain, true, keep_backups);
config_structure (this).write (os, *this);
return true;
} catch (...) {
+4 -1
View File
@@ -147,9 +147,12 @@ public:
* If the configuration file cannot be written, false
* is returned but no exception is thrown.
*
* "keep_backups" is the number of backup files kept.
* By default, no backups are kept.
*
* @return false, if an error occurred.
*/
bool write_config (const std::string &config_file);
bool write_config (const std::string &config_file, int keep_backups = 0);
/**
* @brief Read the configuration from a file