remove shlwapi functions and use stat instead

This commit is contained in:
Thomas Fussell 2016-08-03 08:00:16 -04:00
parent f679f8a8d1
commit 116e53fb0c
2 changed files with 34 additions and 28 deletions

View File

@ -22,21 +22,17 @@
// @author: see AUTHORS file
#include <fstream>
#include <sstream>
#include <detail/include_windows.hpp>
#include <sys/stat.h>
#ifdef __APPLE__
#include <mach-o/dyld.h>
#include <sys/stat.h>
#elif defined(_MSC_VER)
#include <Shlwapi.h>
#elif defined(__linux)
#include <unistd.h>
#include <linux/limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include <detail/include_windows.hpp>
#include <xlnt/utils/path.hpp>
namespace {
@ -54,12 +50,6 @@ bool is_root(const std::string &part)
&& part.front() >= 'A' && part.front() <= 'Z';
}
bool file_exists(const std::string &path_string)
{
std::wstring path_wide(path_string.begin(), path_string.end());
return PathFileExists(path_wide.c_str()) && !PathIsDirectory(path_wide.c_str());
}
std::string get_working_directory()
{
TCHAR buffer[MAX_PATH];
@ -80,22 +70,6 @@ bool is_root(const std::string &part)
return part.empty();
}
bool file_exists(const std::string &path_string)
{
try
{
struct stat fileAtt;
if (stat(path.c_str(), &fileAtt) == 0)
{
return S_ISREG(fileAtt.st_mode);
}
}
catch (...) {}
return false;
}
std::string get_working_directory()
{
std::size_t buffer_size = 100;
@ -153,6 +127,12 @@ std::vector<std::string> split_path_universal(const std::string &path)
return initial;
}
bool file_exists(const std::string &path)
{
struct stat info;
return stat(path.c_str(), &info) == 0 && (info.st_mode & S_IFREG);
}
bool directory_exists(const std::string path)
{
struct stat info;

View File

@ -0,0 +1,26 @@
#pragma once
#include <iostream>
#include <cxxtest/TestSuite.h>
#include <helpers/path_helper.hpp>
#include <helpers/temporary_file.hpp>
#include <xlnt/xlnt.hpp>
class test_path : public CxxTest::TestSuite
{
public:
void test_exists()
{
temporary_file temp;
if (temp.get_path().exists())
{
path_helper::delete_file(temp.get_path());
}
TS_ASSERT(!temp.get_path().exists());
std::ofstream stream(temp.get_path().to_string());
TS_ASSERT(temp.get_path().exists());
}
};