aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-27 18:37:52 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-27 18:37:52 +0000
commitf35292f38aec12b8f1c6a022ccb89fe15dfb5e4a (patch)
treecf49ed71474fb147bd2888d28d7160f7454df570
parent3a8ce32484fe9ec430832af94d9c36fa01380ccc (diff)
downloadpaludis-f35292f38aec12b8f1c6a022ccb89fe15dfb5e4a.tar.gz
paludis-f35292f38aec12b8f1c6a022ccb89fe15dfb5e4a.tar.xz
Add permissions member function to FSEntry. Add optional mode argument to FSEntry mkdir member function. Add unlink member function to FSEntry
-rw-r--r--paludis/util/fs_entry.cc28
-rw-r--r--paludis/util/fs_entry.hh23
2 files changed, 47 insertions, 4 deletions
diff --git a/paludis/util/fs_entry.cc b/paludis/util/fs_entry.cc
index ae6d16f..362befb 100644
--- a/paludis/util/fs_entry.cc
+++ b/paludis/util/fs_entry.cc
@@ -199,6 +199,17 @@ FSEntry::has_permission(const FSUserGroup & user_group, const FSPermission & fs_
throw InternalError(PALUDIS_HERE, "Unhandled FSUserGroup");
}
+mode_t
+FSEntry::permissions() const
+{
+ _stat();
+
+ if (! _exists)
+ throw FSError("Filesystem entry '" + _path + "' does not exist");
+
+ return _stat_info->st_mode;
+}
+
void
FSEntry::_normalise()
{
@@ -338,9 +349,9 @@ FSEntry::file_size() const
}
bool
-FSEntry::mkdir()
+FSEntry::mkdir(mode_t mode)
{
- if (0 == ::mkdir(_path.c_str(), 0755))
+ if (0 == ::mkdir(_path.c_str(), mode))
return true;
int e(errno);
@@ -354,3 +365,16 @@ FSEntry::mkdir()
throw FSError("mkdir '" + _path + "' failed: " + ::strerror(e));
}
+bool
+FSEntry::unlink()
+{
+ if (0 == ::unlink(_path.c_str()))
+ return true;
+
+ int e(errno);
+ if (e == ENOENT)
+ return false;
+ else
+ throw FSError("unlink '" + _path + "' failed: " + ::strerror(e));
+}
+
diff --git a/paludis/util/fs_entry.hh b/paludis/util/fs_entry.hh
index 9d97dbf..6e722c0 100644
--- a/paludis/util/fs_entry.hh
+++ b/paludis/util/fs_entry.hh
@@ -177,12 +177,20 @@ namespace paludis
bool is_symbolic_link() const;
/**
- * Check if filesystem entry has `perm` for `user_group`
+ * 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;
/**
+ * Return the permissions for our item.
+ *
+ * \exception FSError if there was a problem accessing the filesystem entry
+ */
+ mode_t permissions() const;
+
+ /**
* Return the last part of our path (eg '/foo/bar' => 'bar').
*/
std::string basename() const;
@@ -225,7 +233,18 @@ namespace paludis
* \exception FSError If an error other than the directory already
* existing occurs.
*/
- bool mkdir();
+ bool mkdir(mode_t mode = 0755);
+
+ /**
+ * Try to unlink.
+ *
+ * \return True, if we succeeded, and false if we don't exist
+ * already.
+ *
+ * \exception FSError If an error other than us already not
+ * existing occurs.
+ */
+ bool unlink();
/**
* Return the current working directory