use ReplaceFileA directly

This was introduced in Windows 95. exiv2 does not work on older.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
main
Rosen Penev 2 years ago
parent 43ffc614f3
commit 898faffa0d

@ -372,28 +372,17 @@ void FileIo::transfer(BasicIo& src) {
// that file has been opened with FILE_SHARE_DELETE by another process, // that file has been opened with FILE_SHARE_DELETE by another process,
// like a virus scanner or disk indexer // like a virus scanner or disk indexer
// (see also http://stackoverflow.com/a/11023068) // (see also http://stackoverflow.com/a/11023068)
using ReplaceFileA_t = BOOL(WINAPI*)(LPCSTR, LPCSTR, LPCSTR, DWORD, LPVOID, LPVOID); auto ret = ReplaceFileA(pf, fileIo->path().c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr);
HMODULE hKernel = ::GetModuleHandleA("kernel32.dll"); if (ret == 0) {
if (hKernel) { if (GetLastError() != ERROR_FILE_NOT_FOUND)
auto pfcn_ReplaceFileA = reinterpret_cast<ReplaceFileA_t>(GetProcAddress(hKernel, "ReplaceFileA")); throw Error(ErrorCode::kerFileRenameFailed, fileIo->path(), pf, strError());
if (pfcn_ReplaceFileA) { fs::rename(fileIo->path(), pf);
BOOL ret = fs::remove(fileIo->path());
pfcn_ReplaceFileA(pf, fileIo->path().c_str(), nullptr, REPLACEFILE_IGNORE_MERGE_ERRORS, nullptr, nullptr); } else {
if (ret == 0) { if (fileExists(pf) && ::remove(pf) != 0)
if (GetLastError() == ERROR_FILE_NOT_FOUND) { throw Error(ErrorCode::kerCallFailed, pf, strError(), "fs::remove");
fs::rename(fileIo->path(), pf); fs::rename(fileIo->path(), pf);
fs::remove(fileIo->path()); fs::remove(fileIo->path());
} else {
throw Error(ErrorCode::kerFileRenameFailed, fileIo->path(), pf, strError());
}
}
} else {
if (fileExists(pf) && ::remove(pf) != 0) {
throw Error(ErrorCode::kerCallFailed, pf, strError(), "fs::remove");
}
fs::rename(fileIo->path(), pf);
fs::remove(fileIo->path());
}
} }
#else #else
if (fileExists(pf) && fs::remove(pf) != 0) { if (fileExists(pf) && fs::remove(pf) != 0) {

Loading…
Cancel
Save