2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Ensure that std::ofstream is destroyed before renaming.
	* src/SessionSerializer.cc
	* src/util.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-04-13 15:23:31 +00:00
parent c415eb081e
commit aa08af9928
3 changed files with 26 additions and 16 deletions

View File

@ -1,3 +1,9 @@
2010-04-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Ensure that std::ofstream is destroyed before renaming.
* src/SessionSerializer.cc
* src/util.cc
2010-04-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed the bug that user specified path is escaped using

View File

@ -62,14 +62,16 @@ SessionSerializer::SessionSerializer
bool SessionSerializer::save(const std::string& filename) const
{
std::string tempFilename = strconcat(filename, "__temp");
std::ofstream out(tempFilename.c_str(), std::ios::binary);
if(!out) {
return false;
}
save(out);
out.flush();
if(!out) {
return false;
{
std::ofstream out(tempFilename.c_str(), std::ios::binary);
if(!out) {
return false;
}
save(out);
out.flush();
if(!out) {
return false;
}
}
return File(tempFilename).renameTo(filename);
}

View File

@ -1147,14 +1147,16 @@ bool saveAs
return false;
}
std::string tempFilename = strconcat(filename, "__temp");
std::ofstream out(tempFilename.c_str(), std::ios::binary);
if(!out) {
return false;
}
out << data;
out.flush();
if(!out) {
return false;
{
std::ofstream out(tempFilename.c_str(), std::ios::binary);
if(!out) {
return false;
}
out << data;
out.flush();
if(!out) {
return false;
}
}
return File(tempFilename).renameTo(filename);
}