| 2227 | } |
| 2228 | |
| 2229 | void 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" |
no test coverage detected