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

Loading…
Cancel
Save