aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Mark Loeser <halcy0n@gentoo.org> 2006-02-06 14:59:25 +0000
committerAvatar Mark Loeser <halcy0n@gentoo.org> 2006-02-06 14:59:25 +0000
commit0057f20a44280ca564e0142f64dedb847d1ace8b (patch)
tree46ffb3782e6f0ef1ae0999e13bf1ca9685beb5ce
parent1482e34f6d87c6332f6aa9e2419f9a8e160fc36f (diff)
downloadpaludis-0057f20a44280ca564e0142f64dedb847d1ace8b.tar.gz
paludis-0057f20a44280ca564e0142f64dedb847d1ace8b.tar.xz
Make has_permission, ctime, and mtime throw FSError.
-rw-r--r--paludis/fs_entry.cc90
-rw-r--r--paludis/fs_entry.hh3
-rw-r--r--paludis/fs_entry_TEST.cc7
3 files changed, 54 insertions, 46 deletions
diff --git a/paludis/fs_entry.cc b/paludis/fs_entry.cc
index e746b99..5c9af89 100644
--- a/paludis/fs_entry.cc
+++ b/paludis/fs_entry.cc
@@ -142,55 +142,53 @@ FSEntry::has_permission(const FSUserGroup & user_group, const FSPermission & fs_
{
_stat();
- if (_exists)
+ if (! _exists)
+ throw FSError("Filesystem entry does not exist");
+
+ switch (user_group)
{
- switch (user_group)
- {
- case fs_ug_owner:
+ case fs_ug_owner:
+ {
+ switch (fs_perm)
{
- switch (fs_perm)
- {
- case fs_perm_read:
- return (*_stat_info).st_mode & S_IRUSR;
- case fs_perm_write:
- return (*_stat_info).st_mode & S_IWUSR;
- case fs_perm_execute:
- return (*_stat_info).st_mode & S_IXUSR;
- }
- throw InternalError(PALUDIS_HERE, "Unhandled FSPermission");
+ case fs_perm_read:
+ return (*_stat_info).st_mode & S_IRUSR;
+ case fs_perm_write:
+ return (*_stat_info).st_mode & S_IWUSR;
+ case fs_perm_execute:
+ return (*_stat_info).st_mode & S_IXUSR;
}
- case fs_ug_group:
+ throw InternalError(PALUDIS_HERE, "Unhandled FSPermission");
+ }
+ case fs_ug_group:
+ {
+ switch (fs_perm)
{
- switch (fs_perm)
- {
- case fs_perm_read:
- return (*_stat_info).st_mode & S_IRGRP;
- case fs_perm_write:
- return (*_stat_info).st_mode & S_IWGRP;
- case fs_perm_execute:
- return (*_stat_info).st_mode & S_IXGRP;
- }
- throw InternalError(PALUDIS_HERE, "Unhandled FSPermission");
+ case fs_perm_read:
+ return (*_stat_info).st_mode & S_IRGRP;
+ case fs_perm_write:
+ return (*_stat_info).st_mode & S_IWGRP;
+ case fs_perm_execute:
+ return (*_stat_info).st_mode & S_IXGRP;
}
- case fs_ug_others:
+ throw InternalError(PALUDIS_HERE, "Unhandled FSPermission");
+ }
+ case fs_ug_others:
+ {
+ switch (fs_perm)
{
- switch (fs_perm)
- {
- case fs_perm_read:
- return (*_stat_info).st_mode & S_IROTH;
- case fs_perm_write:
- return (*_stat_info).st_mode & S_IWOTH;
- case fs_perm_execute:
- return (*_stat_info).st_mode & S_IXOTH;
- }
- throw InternalError(PALUDIS_HERE, "Unhandled FSPermission");
+ case fs_perm_read:
+ return (*_stat_info).st_mode & S_IROTH;
+ case fs_perm_write:
+ return (*_stat_info).st_mode & S_IWOTH;
+ case fs_perm_execute:
+ return (*_stat_info).st_mode & S_IXOTH;
}
- }
-
- throw InternalError(PALUDIS_HERE, "Unhandled FSUserGroup");
+ throw InternalError(PALUDIS_HERE, "Unhandled FSPermission");
+ }
}
- return false;
+ throw InternalError(PALUDIS_HERE, "Unhandled FSUserGroup");
}
void
@@ -278,10 +276,10 @@ FSEntry::ctime() const
{
_stat();
- if (_exists)
- return (*_stat_info).st_ctime;
+ if (! _exists)
+ throw FSError("Filesystem entry does not exist");
- return false;
+ return (*_stat_info).st_ctime;
}
time_t
@@ -289,8 +287,8 @@ FSEntry::mtime() const
{
_stat();
- if (_exists)
- return (*_stat_info).st_mtime;
+ if (! _exists)
+ throw FSError("Filesystem entry does not exist");
- return false;
+ return (*_stat_info).st_mtime;
}
diff --git a/paludis/fs_entry.hh b/paludis/fs_entry.hh
index 1532657..9b058cf 100644
--- a/paludis/fs_entry.hh
+++ b/paludis/fs_entry.hh
@@ -165,6 +165,7 @@ namespace paludis
/**
* Check if filesystem entry has `perm` for `user_group`
+ * \exception FSError if there was a problem accessing the filesystem entry
*/
bool has_permission(const FSUserGroup & user_group, const FSPermission & fs_perm) const;
@@ -180,11 +181,13 @@ namespace paludis
/**
* Return the time the filesystem entry was created
+ * \exception FSError if there was a problem accessing the filesystem entry
*/
time_t ctime() const;
/**
* Return the time the filesystem entry was last modified
+ * \exception FSError if there was a problem accessing the filesystem entry
*/
time_t mtime() const;
};
diff --git a/paludis/fs_entry_TEST.cc b/paludis/fs_entry_TEST.cc
index 7a417b2..0d81219 100644
--- a/paludis/fs_entry_TEST.cc
+++ b/paludis/fs_entry_TEST.cc
@@ -107,6 +107,7 @@ namespace test_cases
{
FSEntry a("fs_entry_TEST_dir/all_perms");
FSEntry b("fs_entry_TEST_dir/no_perms");
+ FSEntry c("fs_entry_TEST_dir/no_such_file");
TEST_CHECK(a.has_permission(fs_ug_owner, fs_perm_read));
TEST_CHECK(a.has_permission(fs_ug_owner, fs_perm_write));
@@ -127,6 +128,8 @@ namespace test_cases
TEST_CHECK(!b.has_permission(fs_ug_others, fs_perm_read));
TEST_CHECK(!b.has_permission(fs_ug_others, fs_perm_write));
TEST_CHECK(!b.has_permission(fs_ug_others, fs_perm_execute));
+
+ TEST_CHECK_THROWS(c.has_permission(fs_ug_owner, fs_perm_read), FSError);
}
} test_fs_entry_permission;
@@ -141,11 +144,15 @@ namespace test_cases
{
FSEntry a("fs_entry_TEST_dir");
FSEntry b("fs_entry_TEST_dir/no_perms");
+ FSEntry c("fs_entry_TEST_dir/no_such_file");
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_CHECK_THROWS(c.ctime(), FSError);
+ TEST_CHECK_THROWS(c.mtime(), FSError);
}
} test_fs_entry_time;
}