From ec9518fc4d5ac1079f3b7958ad0f12460235e52b Mon Sep 17 00:00:00 2001 From: Geoffrey Merck Date: Tue, 17 Sep 2024 20:58:39 +0200 Subject: [PATCH] Handle unable to copy downloaded file #50 --- Common/HostsFileDownloader.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Common/HostsFileDownloader.cpp b/Common/HostsFileDownloader.cpp index 74fdb29..765f6b0 100644 --- a/Common/HostsFileDownloader.cpp +++ b/Common/HostsFileDownloader.cpp @@ -59,10 +59,17 @@ bool CHostsFileDownloader::download(const std::string & hostsFileURL, const std: if(ok) { outFileName = std::string(outFileNameBuf); - ok = ok && std::filesystem::copy_file(outFileName, hostFilePath, std::filesystem::copy_options::overwrite_existing); - if(!ok) { - CLog::logError("Failed to copy host file to %s", hostFilePath.c_str()); + + try + { + std::filesystem::copy_file(outFileName, hostFilePath, std::filesystem::copy_options::overwrite_existing); + } + catch(std::filesystem::filesystem_error& e) + { + ok = false; + CLog::logError("Failed to copy host file to %s: %s", hostFilePath.c_str(), e.what()); } + } else { CLog::logWarning("Failed to download Host file from %s, using previous file", hostsFileURL.c_str()); }