aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mark Loeser <halcy0n@gentoo.org> 2006-01-26 23:53:00 +0000
committerAvatar Mark Loeser <halcy0n@gentoo.org> 2006-01-26 23:53:00 +0000
commitc50dc284691fd1318d278a2a599b4a2d54dcfc5a (patch)
tree2eeefa682d2b164930aab48bce479cf89d5b1d70
parent192bbcfc2568b8f1123a77f452e29ed370af4a45 (diff)
downloadpaludis-c50dc284691fd1318d278a2a599b4a2d54dcfc5a.tar.gz
paludis-c50dc284691fd1318d278a2a599b4a2d54dcfc5a.tar.xz
Only call stat() when necessary now, instead of each time we construct an FSEntry
-rw-r--r--paludis/fs_entry.cc40
-rw-r--r--paludis/fs_entry.hh11
2 files changed, 43 insertions, 8 deletions
diff --git a/paludis/fs_entry.cc b/paludis/fs_entry.cc
index fa8356d..9c187c9 100644
--- a/paludis/fs_entry.cc
+++ b/paludis/fs_entry.cc
@@ -45,17 +45,18 @@ FSError::FSError(const std::string & message) throw () :
FSEntry::FSEntry(const std::string & path) :
ComparisonPolicyType(&FSEntry::_path),
_path(path),
- _stat_info(new struct stat)
+ _stat_info(new struct stat),
+ _checked(false)
{
_normalise();
- _stat();
}
FSEntry::FSEntry(const FSEntry & other) :
ComparisonPolicyType(&FSEntry::_path),
_path(other._path),
_stat_info(other._stat_info),
- _exists(other._exists)
+ _exists(other._exists),
+ _checked(other._checked)
{
}
@@ -93,7 +94,7 @@ FSEntry::operator/= (const FSEntry & rhs)
_path.append("/");
_path.append(rhs._path);
_normalise();
- _stat();
+ _checked = false;
return *this;
}
@@ -101,12 +102,16 @@ FSEntry::operator/= (const FSEntry & rhs)
bool
FSEntry::exists() const
{
+ _stat();
+
return _exists;
}
bool
FSEntry::is_directory() const
{
+ _stat();
+
if(_exists)
return S_ISDIR((*_stat_info).st_mode);
@@ -116,6 +121,8 @@ FSEntry::is_directory() const
bool
FSEntry::is_regular_file() const
{
+ _stat();
+
if(_exists)
return S_ISREG((*_stat_info).st_mode);
@@ -125,6 +132,8 @@ FSEntry::is_regular_file() const
bool
FSEntry::owner_has_read() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IRUSR;
@@ -134,6 +143,8 @@ FSEntry::owner_has_read() const
bool
FSEntry::owner_has_write() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IWUSR;
@@ -143,6 +154,8 @@ FSEntry::owner_has_write() const
bool
FSEntry::owner_has_execute() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IXUSR;
@@ -152,6 +165,8 @@ FSEntry::owner_has_execute() const
bool
FSEntry::group_has_read() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IRGRP;
@@ -161,6 +176,8 @@ FSEntry::group_has_read() const
bool
FSEntry::group_has_write() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IWGRP;
@@ -170,6 +187,8 @@ FSEntry::group_has_write() const
bool
FSEntry::group_has_execute() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IXGRP;
@@ -179,6 +198,8 @@ FSEntry::group_has_execute() const
bool
FSEntry::others_has_read() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IROTH;
@@ -188,6 +209,8 @@ FSEntry::others_has_read() const
bool
FSEntry::others_has_write() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IWOTH;
@@ -197,6 +220,8 @@ FSEntry::others_has_write() const
bool
FSEntry::others_has_execute() const
{
+ _stat();
+
if(_exists)
return (*_stat_info).st_mode & S_IXOTH;
@@ -239,8 +264,11 @@ FSEntry::_normalise()
}
void
-FSEntry::_stat()
+FSEntry::_stat() const
{
+ if(_checked == true)
+ return;
+
if (0 != stat(_path.c_str(), _stat_info.raw_pointer()))
{
if (errno != ENOENT)
@@ -251,6 +279,8 @@ FSEntry::_stat()
}
else
_exists = true;
+
+ _checked = true;
}
std::string
diff --git a/paludis/fs_entry.hh b/paludis/fs_entry.hh
index 78fa1c5..2555c09 100644
--- a/paludis/fs_entry.hh
+++ b/paludis/fs_entry.hh
@@ -64,13 +64,18 @@ namespace paludis
private:
std::string _path;
- CountedPtr<struct stat, count_policy::ExternalCountTag> _stat_info;
+ mutable CountedPtr<struct stat, count_policy::ExternalCountTag> _stat_info;
- bool _exists;
+ mutable bool _exists;
+
+ /**
+ * Whether or not we have run _stat() on this location yet
+ */
+ mutable bool _checked;
void _normalise();
- void _stat();
+ void _stat() const;
public:
/**