| 841 | } |
| 842 | |
| 843 | bool Path_WriteStringToTextFileAtomic( const std::string &strFilename, const char *pchData ) |
| 844 | { |
| 845 | std::string strTmpFilename = strFilename + ".tmp"; |
| 846 | |
| 847 | if ( !Path_WriteStringToTextFile( strTmpFilename, pchData ) ) |
| 848 | return false; |
| 849 | |
| 850 | // Platform specific atomic file replacement |
| 851 | #if defined( _WIN32 ) |
| 852 | std::wstring wsFilename = UTF8to16( strFilename.c_str() ); |
| 853 | std::wstring wsTmpFilename = UTF8to16( strTmpFilename.c_str() ); |
| 854 | if ( !::ReplaceFileW( wsFilename.c_str(), wsTmpFilename.c_str(), nullptr, 0, 0, 0 ) ) |
| 855 | { |
| 856 | // if we couldn't ReplaceFile, try a non-atomic write as a fallback |
| 857 | if ( !Path_WriteStringToTextFile( strFilename, pchData ) ) |
| 858 | return false; |
| 859 | } |
| 860 | #elif defined( POSIX ) |
| 861 | if ( rename( strTmpFilename.c_str(), strFilename.c_str() ) == -1 ) |
| 862 | return false; |
| 863 | #else |
| 864 | #error Do not know how to write atomic file |
| 865 | #endif |
| 866 | |
| 867 | return true; |
| 868 | } |
| 869 | |
| 870 | |
| 871 | #if defined(WIN32) |
nothing calls this directly
no test coverage detected