Use `std::filesystem` in `createBackupFile`
* Drop platform-specific code * Avoid using ANSI WinAPI function
This commit is contained in:
parent
751ace8810
commit
8a48914bcc
|
@ -186,6 +186,9 @@ set(CONFIGURATION_PACKAGE_SUFFIX
|
|||
find_package(c++utilities${CONFIGURATION_PACKAGE_SUFFIX} 5.10.0 REQUIRED)
|
||||
use_cpp_utilities(VISIBILITY PUBLIC)
|
||||
|
||||
# link against a possibly required extra library for std::filesystem
|
||||
use_standard_filesystem()
|
||||
|
||||
# find 3rd party libraries
|
||||
include(3rdParty)
|
||||
# zlib
|
||||
|
|
|
@ -5,13 +5,8 @@
|
|||
#include <c++utilities/conversion/stringbuilder.h>
|
||||
#include <c++utilities/conversion/stringconversion.h>
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
@ -155,12 +150,7 @@ void createBackupFile(const std::string &backupDir, const std::string &originalP
|
|||
}
|
||||
|
||||
// test whether the backup path is still unused; otherwise continue loop
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
if (GetFileAttributes(BasicFileInfo::pathForOpen(backupPath).data()) == INVALID_FILE_ATTRIBUTES) {
|
||||
#else
|
||||
struct stat backupStat;
|
||||
if (stat(BasicFileInfo::pathForOpen(backupPath).data(), &backupStat)) {
|
||||
#endif
|
||||
if (auto ec = std::error_code(); !std::filesystem::exists(BasicFileInfo::pathForOpen(backupPath), ec)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue