-Werror=shadow-field to prevent YAML namespace collisions; atomic FileWriter

This commit is contained in:
Jack Andersen 2017-11-25 17:02:50 -10:00
parent 26a0c4b46f
commit cf3baad905
3 changed files with 13 additions and 2 deletions

View File

@ -2418,6 +2418,7 @@ int main(int argc, const char** argv)
"-D__atdna__=1", "-D__atdna__=1",
"-Wno-expansion-to-defined", "-Wno-expansion-to-defined",
"-Wno-nullability-completeness", "-Wno-nullability-completeness",
"-Werror=shadow-field",
"-I" XSTR(INSTALL_PREFIX) "/lib/clang/" CLANG_VERSION_STRING "/include", "-I" XSTR(INSTALL_PREFIX) "/lib/clang/" CLANG_VERSION_STRING "/include",
"-I" XSTR(INSTALL_PREFIX) "/include/Athena"}; "-I" XSTR(INSTALL_PREFIX) "/include/Athena"};
for (int a=1 ; a<argc ; ++a) for (int a=1 ; a<argc ; ++a)

View File

@ -46,7 +46,10 @@ FileWriter::~FileWriter()
void FileWriter::open(bool overwrite) void FileWriter::open(bool overwrite)
{ {
if (overwrite) if (overwrite)
m_fileHandle = fopen(m_filename.c_str(), "w+b"); {
std::string tmpFilename = m_filename + '~';
m_fileHandle = fopen(tmpFilename.c_str(), "w+b");
}
else else
{ {
m_fileHandle = fopen(m_filename.c_str(), "a+b"); m_fileHandle = fopen(m_filename.c_str(), "a+b");
@ -81,6 +84,9 @@ void FileWriter::close()
fclose(m_fileHandle); fclose(m_fileHandle);
m_fileHandle = NULL; m_fileHandle = NULL;
std::string tmpFilename = m_filename + '~';
rename(tmpFilename.c_str(), m_filename.c_str());
} }
void FileWriter::seek(atInt64 pos, SeekOrigin origin) void FileWriter::seek(atInt64 pos, SeekOrigin origin)

View File

@ -36,7 +36,8 @@ void FileWriter::open(bool overwrite)
{ {
if (overwrite) if (overwrite)
{ {
m_fileHandle = CreateFileW(m_filename.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE, std::wstring tmpFilename = m_filename + L'~';
m_fileHandle = CreateFileW(tmpFilename.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
} }
else else
@ -72,6 +73,9 @@ void FileWriter::close()
FlushFileBuffers(m_fileHandle); FlushFileBuffers(m_fileHandle);
CloseHandle(m_fileHandle); CloseHandle(m_fileHandle);
m_fileHandle = 0; m_fileHandle = 0;
std::wstring tmpFilename = m_filename + L'~';
MoveFileExW(tmpFilename.c_str(), m_filename.c_str(), MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
} }
void FileWriter::seek(atInt64 pos, SeekOrigin origin) void FileWriter::seek(atInt64 pos, SeekOrigin origin)