From: dooglus Date: Sun, 24 Feb 2008 20:50:18 +0000 (+0000) Subject: Move more code inside the 'try' block in an attempt to have studio not crash when... X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=9d5f68b3c238f7438b12d8937a6e4a26bcfb2c99;p=synfig.git Move more code inside the 'try' block in an attempt to have studio not crash when it can't write auto-save files. git-svn-id: http://svn.voria.com/code@1812 1f10aa63-cdf2-0310-b900-c93c546f37ac --- diff --git a/synfig-core/trunk/src/synfig/savecanvas.cpp b/synfig-core/trunk/src/synfig/savecanvas.cpp index eb2bf75..5f18473 100644 --- a/synfig-core/trunk/src/synfig/savecanvas.cpp +++ b/synfig-core/trunk/src/synfig/savecanvas.cpp @@ -768,29 +768,28 @@ synfig::save_canvas(const String &filename, Canvas::ConstHandle canvas) encode_canvas_toplevel(document.create_root_node("canvas"),canvas); document.write_to_file_formatted(tmp_filename); - } - catch(...) { synfig::error("synfig::save_canvas(): Caught unknown exception"); return false; } - #ifdef _WIN32 - // On Win32 platforms, rename() has bad behavior. work around it. - char old_file[80]="sif.XXXXXXXX"; - mktemp(old_file); - rename(filename.c_str(),old_file); - if(rename(tmp_filename.c_str(),filename.c_str())!=0) - { - rename(old_file,tmp_filename.c_str()); - synfig::error("synfig::save_canvas(): Unable to rename file to correct filename, errno=%d",errno); - return false; - } - remove(old_file); + // On Win32 platforms, rename() has bad behavior. work around it. + char old_file[80]="sif.XXXXXXXX"; + mktemp(old_file); + rename(filename.c_str(),old_file); + if(rename(tmp_filename.c_str(),filename.c_str())!=0) + { + rename(old_file,tmp_filename.c_str()); + synfig::error("synfig::save_canvas(): Unable to rename file to correct filename, errno=%d",errno); + return false; + } + remove(old_file); #else - if(rename(tmp_filename.c_str(),filename.c_str())!=0) - { - synfig::error("synfig::save_canvas(): Unable to rename file to correct filename, errno=%d",errno); - return false; - } + if(rename(tmp_filename.c_str(),filename.c_str())!=0) + { + synfig::error("synfig::save_canvas(): Unable to rename file to correct filename, errno=%d",errno); + return false; + } #endif + } + catch(...) { synfig::error("synfig::save_canvas(): Caught unknown exception"); return false; } return true; }