| 207 | } |
| 208 | |
| 209 | bool atomic_replace_file(const std::string &from_path, const std::string &to_path) { |
| 210 | #if defined(_WIN32) |
| 211 | auto wfrom_path = FileStream::utf8_to_utf16(expand_path(from_path)); |
| 212 | auto wto_path = FileStream::utf8_to_utf16(expand_path(to_path)); |
| 213 | // Maximizing chances for success |
| 214 | DWORD attributes = GetFileAttributesW(wto_path.c_str()); |
| 215 | if (INVALID_FILE_ATTRIBUTES != attributes) |
| 216 | SetFileAttributesW(wto_path.c_str(), attributes & (~FILE_ATTRIBUTE_READONLY)); |
| 217 | bool ok = MoveFileExW(wfrom_path.c_str(), wto_path.c_str(), MOVEFILE_REPLACE_EXISTING) != 0; |
| 218 | // int code = ok ? 0 : static_cast<int>(::GetLastError()); |
| 219 | #else |
| 220 | bool ok = std::rename(expand_path(from_path).c_str(), expand_path(to_path).c_str()) == 0; |
| 221 | // int code = ok ? 0 : errno; |
| 222 | #endif |
| 223 | // if(err) *err = std::error_code(code, std::system_category()); |
| 224 | return ok; |
| 225 | } |
| 226 | bool copy_file(const std::string &from_path, const std::string &to_path) { |
| 227 | platform::FileStream from(from_path, platform::O_READ_EXISTING); |
| 228 | platform::FileStream to(to_path, platform::O_CREATE_ALWAYS); |
no test coverage detected