add Path::exists()
This commit is contained in:
parent
b55d8d0f09
commit
e3cb7b15b4
@ -14,6 +14,7 @@ namespace jes
|
|||||||
Path dirname();
|
Path dirname();
|
||||||
Path join(const Path & other);
|
Path join(const Path & other);
|
||||||
const std::string & to_s() { return m_path; }
|
const std::string & to_s() { return m_path; }
|
||||||
|
bool exists();
|
||||||
protected:
|
protected:
|
||||||
void clean();
|
void clean();
|
||||||
std::string m_path;
|
std::string m_path;
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
#include "jes/Path.h"
|
#include "jes/Path.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
namespace jes
|
namespace jes
|
||||||
{
|
{
|
||||||
@ -46,6 +49,12 @@ namespace jes
|
|||||||
return Path(m_path + '/' + other.m_path);
|
return Path(m_path + '/' + other.m_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Path::exists()
|
||||||
|
{
|
||||||
|
struct stat st;
|
||||||
|
return stat(m_path.c_str(), &st) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
void Path::clean()
|
void Path::clean()
|
||||||
{
|
{
|
||||||
for (char & c : m_path)
|
for (char & c : m_path)
|
||||||
|
@ -38,3 +38,9 @@ TEST(PathTest, dirname)
|
|||||||
EXPECT_EQ(".", Path("folder//").dirname().to_s());
|
EXPECT_EQ(".", Path("folder//").dirname().to_s());
|
||||||
EXPECT_EQ("a", Path("a/b").dirname().to_s());
|
EXPECT_EQ("a", Path("a/b").dirname().to_s());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(PathTest, exists)
|
||||||
|
{
|
||||||
|
EXPECT_TRUE(Path("runtime").exists());
|
||||||
|
EXPECT_FALSE(Path("foobar").exists());
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user