Use utils::file::exists instead of std::filesystem

This commit is contained in:
badaix 2021-12-18 22:48:39 +01:00
parent 98ccc8eded
commit 3f208d260e
5 changed files with 29 additions and 23 deletions

View file

@ -32,7 +32,6 @@
#include <unistd.h>
#endif
#include <filesystem>
#include <fstream>
#include <stdexcept>
#include <vector>
@ -44,13 +43,26 @@ namespace file
{
static bool exists(const std::string& filename)
{
if (filename.empty())
return false;
#ifdef WINDOWS
DWORD dwAttrib = GetFileAttributes(filename.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES);
#else
struct stat buffer;
return (stat(filename.c_str(), &buffer) == 0);
#endif
}
#ifndef WINDOWS
static void do_chown(const std::string& file_path, const std::string& user_name, const std::string& group_name)
{
if (user_name.empty() && group_name.empty())
return;
if (!std::filesystem::exists(file_path))
if (!utils::file::exists(file_path))
return;
uid_t uid = -1;