MCPcopy Create free account
hub / github.com/comaps/comaps / SaveCountriesToWritableDirAtomic

Function SaveCountriesToWritableDirAtomic

libs/storage/storage.cpp:128–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

126namespace
127{
128bool 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
160void Storage::ApplyCountriesInMemory(std::string const & buffer)

Callers 1

Calls 7

JoinPathFunction · 0.85
RenameFileXFunction · 0.85
RemoveFileIfExistsMethod · 0.80
WriteMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
DisableBackupForFileMethod · 0.45

Tested by

no test coverage detected