mirror of
https://github.com/KLayout/klayout.git
synced 2026-09-07 03:21:34 +02:00
Issue 720 (#721)
* Implemented a backup scheme for the file writer. * Also consider backup files when the writer fails. * Removed test exception * Added config option for number of backups.
This commit is contained in:
@@ -317,14 +317,14 @@ static void delete_layers2 (lay::LayoutView *view, unsigned int index, const std
|
||||
|
||||
static void save_as1 (lay::LayoutView *view, unsigned int index, const std::string &filename, const db::SaveLayoutOptions &options)
|
||||
{
|
||||
view->save_as (index, filename, tl::OutputStream::OM_Auto, options, true);
|
||||
view->save_as (index, filename, tl::OutputStream::OM_Auto, options, true, 0);
|
||||
}
|
||||
|
||||
static void save_as2 (lay::LayoutView *view, unsigned int index, const std::string &filename, bool /*gzip*/, const db::SaveLayoutOptions &options)
|
||||
{
|
||||
// because set_format_from_name always returns true now, we ignore the gzip option -
|
||||
// it's probably used only in that context.
|
||||
view->save_as (index, filename, tl::OutputStream::OM_Auto, options, true);
|
||||
view->save_as (index, filename, tl::OutputStream::OM_Auto, options, true, 0);
|
||||
}
|
||||
|
||||
#if defined(HAVE_QTBINDINGS)
|
||||
|
||||
@@ -297,7 +297,7 @@ LayoutHandle::update_save_options (db::SaveLayoutOptions &options)
|
||||
}
|
||||
|
||||
void
|
||||
LayoutHandle::save_as (const std::string &fn, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update)
|
||||
LayoutHandle::save_as (const std::string &fn, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update, int keep_backups)
|
||||
{
|
||||
if (update) {
|
||||
|
||||
@@ -321,8 +321,13 @@ LayoutHandle::save_as (const std::string &fn, tl::OutputStream::OutputStreamMode
|
||||
{
|
||||
// The write needs to be finished before the file watcher gets the new modification time
|
||||
db::Writer writer (options);
|
||||
tl::OutputStream stream (fn, om);
|
||||
writer.write (*mp_layout, stream);
|
||||
tl::OutputStream stream (fn, om, false, keep_backups);
|
||||
try {
|
||||
writer.write (*mp_layout, stream);
|
||||
} catch (...) {
|
||||
stream.reject ();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
if (update) {
|
||||
|
||||
@@ -212,7 +212,7 @@ public:
|
||||
* Save the layout under the given file name and with the given options.
|
||||
* If update is true, this method updates the cell view's filename, title, save options and dirty flag.
|
||||
*/
|
||||
void save_as (const std::string &filename, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update = true);
|
||||
void save_as (const std::string &filename, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update = true, int keep_backups = 0);
|
||||
|
||||
/**
|
||||
* @brief Sets the save options and a flag indicating whether they are valid
|
||||
|
||||
@@ -2216,12 +2216,12 @@ LayoutView::signal_selection_changed ()
|
||||
}
|
||||
|
||||
void
|
||||
LayoutView::save_as (unsigned int index, const std::string &filename, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update)
|
||||
LayoutView::save_as (unsigned int index, const std::string &filename, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update, int keep_backups)
|
||||
{
|
||||
tl_assert (index < cellviews ());
|
||||
|
||||
tl::SelfTimer timer (tl::verbosity () >= 11, tl::to_string (QObject::tr ("Saving")));
|
||||
cellview (index)->save_as (filename, om, options, update);
|
||||
cellview (index)->save_as (filename, om, options, update, keep_backups);
|
||||
|
||||
cellview_changed (index);
|
||||
}
|
||||
|
||||
@@ -826,7 +826,7 @@ public:
|
||||
* @brief Save the given cellview into the given file (with options)
|
||||
* If "update" is true, the cell view's properties will be updated (options, filename etc.).
|
||||
*/
|
||||
void save_as (unsigned int index, const std::string &filename, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update);
|
||||
void save_as (unsigned int index, const std::string &filename, tl::OutputStream::OutputStreamMode om, const db::SaveLayoutOptions &options, bool update, int keep_backups);
|
||||
|
||||
/**
|
||||
* @brief Implementation of the undo operations
|
||||
|
||||
Reference in New Issue
Block a user