MCPcopy Create free account
hub / github.com/apple/foundationdb / renameFile

Function renameFile

flow/Platform.actor.cpp:2229–2249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2227}
2228
2229void renameFile(std::string const& fromPath, std::string const& toPath) {
2230 INJECT_FAULT(io_error, "renameFile"); // rename file failed
2231#ifdef _WIN32
2232 if (MoveFileExA(fromPath.c_str(),
2233 toPath.c_str(),
2234 MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH)) {
2235 // renamedFile();
2236 return;
2237 }
2238#elif (defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__))
2239 if (!rename(fromPath.c_str(), toPath.c_str())) {
2240 // FIXME: We cannot inject faults after renaming the file, because we could end up with two asyncFileNonDurable
2241 // open for the same file renamedFile();
2242 return;
2243 }
2244#else
2245#error Port me!
2246#endif
2247 TraceEvent(SevError, "RenameFile").detail("FromPath", fromPath).detail("ToPath", toPath).GetLastError();
2248 throw io_error();
2249}
2250
2251#if defined(__linux__)
2252#define FOPEN_CLOEXEC_MODE "e"

Callers 8

closeMethod · 0.85
cleanupTraceFilesMethod · 0.85
openMethod · 0.85
restoreRoleFilesHelperFunction · 0.85
renameFileMethod · 0.85
sync_implMethod · 0.85
renameFileMethod · 0.85

Calls 3

TraceEventClass · 0.85
detailMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected