MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / overwriteFileWithRename

Method overwriteFileWithRename

source/core/StarFile_windows.cpp:227–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227void File::overwriteFileWithRename(char const* data, size_t len, String const& filename, String const& newSuffix) {
228 String newFile = filename + newSuffix;
229
230 try {
231 auto file = File::open(newFile, IOMode::Write | IOMode::Truncate);
232 file->writeFull(data, len);
233 file->sync();
234 file->close();
235
236 File::rename(newFile, filename);
237 } catch (IOException const&) {
238 // HACK: Been having trouble on windows with the write / flush / move
239 // sequence, try super hard to just write the file non-atomically in case
240 // of weird file locking problems instead of erroring.
241
242 // Ignore any error on removal of the maybe existing newFile
243 ::_wremove(stringToUtf16(newFile).get());
244
245 writeFile(data, len, filename);
246 }
247}
248
249void* File::fopen(char const* filename, IOMode mode) {
250 DWORD desiredAccess = 0;

Callers

nothing calls this directly

Calls 5

stringToUtf16Function · 0.85
writeFullMethod · 0.80
syncMethod · 0.45
closeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected