mirror of https://github.com/libAthena/athena.git
-Werror=shadow-field to prevent YAML namespace collisions; atomic FileWriter
This commit is contained in:
parent
26a0c4b46f
commit
cf3baad905
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue