| 126 | namespace |
| 127 | { |
| 128 | bool SaveCountriesToWritableDirAtomic(std::string const & buffer) |
| 129 | { |
| 130 | auto & pl = GetPlatform(); |
| 131 | std::string const finalPath = base::JoinPath(pl.WritableDir(), COUNTRIES_FILE); |
| 132 | std::string const tmpPath = finalPath + EXTENSION_TMP; |
| 133 | |
| 134 | try |
| 135 | { |
| 136 | FileWriter w(tmpPath); |
| 137 | w.Write(buffer.data(), buffer.size()); |
| 138 | } |
| 139 | catch (...) |
| 140 | { |
| 141 | LOG(LWARNING, ("COUNTRIES: write tmp failed:", tmpPath)); |
| 142 | pl.RemoveFileIfExists(tmpPath); |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | pl.RemoveFileIfExists(finalPath); |
| 147 | if (!base::RenameFileX(tmpPath, finalPath)) |
| 148 | { |
| 149 | LOG(LWARNING, ("COUNTRIES: rename failed:", tmpPath, "->", finalPath)); |
| 150 | pl.RemoveFileIfExists(tmpPath); |
| 151 | return false; |
| 152 | } |
| 153 | |
| 154 | pl.DisableBackupForFile(finalPath); |
| 155 | LOG(LINFO, ("COUNTRIES: saved to:", finalPath)); |
| 156 | return true; |
| 157 | } |
| 158 | } // namespace |
| 159 | |
| 160 | void Storage::ApplyCountriesInMemory(std::string const & buffer) |
no test coverage detected