aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mark Loeser <halcy0n@gentoo.org> 2006-02-04 21:43:37 +0000
committerAvatar Mark Loeser <halcy0n@gentoo.org> 2006-02-04 21:43:37 +0000
commit7f8bc0c685575320389768561d861a2d16733d58 (patch)
tree489a92877c2e57c2da1f7247b55b3770e2dfbf57
parentbda262d789e12fc082b955ed0de4fe2a6607797e (diff)
downloadpaludis-7f8bc0c685575320389768561d861a2d16733d58.tar.gz
paludis-7f8bc0c685575320389768561d861a2d16733d58.tar.xz
Add FSEntry::ctime() and mtime()
-rw-r--r--paludis/fs_entry.cc20
-rw-r--r--paludis/fs_entry.hh10
-rw-r--r--paludis/fs_entry_TEST.cc20
3 files changed, 50 insertions, 0 deletions
diff --git a/paludis/fs_entry.cc b/paludis/fs_entry.cc
index 2ea8f9c..e746b99 100644
--- a/paludis/fs_entry.cc
+++ b/paludis/fs_entry.cc
@@ -273,4 +273,24 @@ paludis::operator<< (std::ostream & s, const FSEntry & f)
return s;
}
+time_t
+FSEntry::ctime() const
+{
+ _stat();
+
+ if (_exists)
+ return (*_stat_info).st_ctime;
+
+ return false;
+}
+time_t
+FSEntry::mtime() const
+{
+ _stat();
+
+ if (_exists)
+ return (*_stat_info).st_mtime;
+
+ return false;
+}
diff --git a/paludis/fs_entry.hh b/paludis/fs_entry.hh
index 2a5749c..1532657 100644
--- a/paludis/fs_entry.hh
+++ b/paludis/fs_entry.hh
@@ -177,6 +177,16 @@ namespace paludis
* Return the canonicalised version of our path.
*/
FSEntry realpath() const;
+
+ /**
+ * Return the time the filesystem entry was created
+ */
+ time_t ctime() const;
+
+ /**
+ * Return the time the filesystem entry was last modified
+ */
+ time_t mtime() const;
};
/**
diff --git a/paludis/fs_entry_TEST.cc b/paludis/fs_entry_TEST.cc
index ed9cb3b..7a417b2 100644
--- a/paludis/fs_entry_TEST.cc
+++ b/paludis/fs_entry_TEST.cc
@@ -21,6 +21,7 @@
#include "fs_entry.hh"
#include <test/test_framework.hh>
#include <test/test_runner.hh>
+#include <ctime>
using namespace paludis;
using namespace test;
@@ -128,4 +129,23 @@ namespace test_cases
TEST_CHECK(!b.has_permission(fs_ug_others, fs_perm_execute));
}
} test_fs_entry_permission;
+
+ /**
+ * \test Test FSEntry ctime and mtime methods
+ */
+ struct FSEntryTime: TestCase
+ {
+ FSEntryTime() : TestCase("ctime and mtime") {}
+
+ void run()
+ {
+ FSEntry a("fs_entry_TEST_dir");
+ FSEntry b("fs_entry_TEST_dir/no_perms");
+
+ TEST_CHECK(a.ctime() <= std::time(NULL));
+ TEST_CHECK((a.mtime() >= a.ctime()) && (a.mtime() <= std::time(NULL)));
+ TEST_CHECK(b.ctime() <= std::time(NULL));
+ TEST_CHECK((b.mtime() >= b.ctime()) && (b.mtime() <= std::time(NULL)));
+ }
+ } test_fs_entry_time;
}