// otherwise false.
operator bool() const;
+ // Return the path that this stat result refers to.
+ const std::string& path() const;
+
// Return whether this object refers to the same device and i-node as `other`
// does.
bool same_inode_as(const Stat& other) const;
Stat(StatFunction stat_function, const std::string& path, OnError on_error);
private:
+ std::string m_path;
stat_t m_stat;
int m_errno;
return m_errno == 0 && device() == other.device() && inode() == other.inode();
}
+inline const std::string&
+Stat::path() const
+{
+ return m_path;
+}
+
inline int
Stat::error_number() const
{
CHECK(!Stat::stat("nonexistent").same_inode_as(Stat::stat("nonexistent")));
}
+TEST_CASE("Get path")
+{
+ TestContext test_context;
+
+ util::write_file("a", "");
+ CHECK(Stat::stat("a").path() == "a");
+ CHECK(Stat::stat("does_not_exist").path() == "does_not_exist");
+}
+
TEST_CASE("Return values when file is missing")
{
auto stat = Stat::stat("does_not_exist");