Skip to content

Commit

Permalink
Remove temporary file at safeWriteToFile()
Browse files Browse the repository at this point in the history
  • Loading branch information
selat authored and sapier committed Aug 16, 2014
1 parent f6e01ad commit 5f1f115
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/filesys.cpp
Expand Up @@ -701,16 +701,19 @@ bool safeWriteToFile(const std::string &path, const std::string &content)
os << content;
os.flush();
os.close();
if (os.fail())
if (os.fail()) {
remove(tmp_file.c_str());
return false;
}

// Copy file
#ifdef _WIN32
remove(path.c_str());
return (rename(tmp_file.c_str(), path.c_str()) == 0);
#else
return (rename(tmp_file.c_str(), path.c_str()) == 0);
#endif
if(rename(tmp_file.c_str(), path.c_str())) {
remove(tmp_file.c_str());
return false;
} else {
return true;
}
}

} // namespace fs
Expand Down

0 comments on commit 5f1f115

Please sign in to comment.