From ce94b5c7fcb980fb171c7f45b522364c225d6dd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Sun, 8 Mar 2009 21:12:02 +0100 Subject: [PATCH] work around bug #12450... (boost issue previously marked as 'upstream problem') by not using boost iostreams to write directly to disk, instead, write to a stringstream and thenoutput that to a file. This makes Wesnoth no longer hang when a save is issued with insufficient disk space. --- src/gamestatus.cpp | 13 ++++++++++--- src/replay.cpp | 15 +++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index bb8b36b9a4f..ae779d7fb1e 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -927,9 +927,16 @@ void save_game(const game_state& gamestate) } scoped_ostream os(open_save_game(filename)); - config_writer out(*os, preferences::compress_saves()); - write_game(out, gamestate); - finish_save_game(out, gamestate, gamestate.label); + std::stringstream ss; + { + config_writer out(ss, preferences::compress_saves()); + write_game(out, gamestate); + finish_save_game(out, gamestate, gamestate.label); + } + (*os) << ss.str(); + if (!os->good()) { + throw game::save_game_failed(_("Could not write to file")); + } } namespace { diff --git a/src/replay.cpp b/src/replay.cpp index 90e187f4220..3fdaafc05d6 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -26,6 +26,7 @@ #include "game_end_exceptions.hpp" #include "game_preferences.hpp" #include "game_events.hpp" +#include "gettext.hpp" #include "log.hpp" #include "map.hpp" #include "map_label.hpp" @@ -212,13 +213,19 @@ void replay::save_game(const std::string& label, const config& snapshot, filename += ".gz"; } + std::stringstream ss; + { + config_writer out(ss, preferences::compress_saves()); + ::write_game(out, saveInfo_); + finish_save_game(out, saveInfo_, saveInfo_.label); + } scoped_ostream os(open_save_game(filename)); - config_writer out(*os, preferences::compress_saves()); - ::write_game(out, saveInfo_); - finish_save_game(out, saveInfo_, saveInfo_.label); - + (*os) << ss.str(); saveInfo_.replay_data = config(); saveInfo_.snapshot = config(); + if (!os->good()) { + throw game::save_game_failed(_("Could not write to file")); + } } void replay::add_unit_checksum(const map_location& loc,config* const cfg)