aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-27 21:10:15 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-06-27 21:10:15 +0000
commit9b90e4845a1c06cc609310da04c9585e13a3705f (patch)
tree51861064d495441ebc688e1b920f099630b07531
parent30cf2d013179e7e5e9129cf2a669f99774dc2be9 (diff)
downloadpaludis-9b90e4845a1c06cc609310da04c9585e13a3705f.tar.gz
paludis-9b90e4845a1c06cc609310da04c9585e13a3705f.tar.xz
Add chown, group, owner member function to FSEntry
-rw-r--r--paludis/util/fs_entry.cc30
-rw-r--r--paludis/util/fs_entry.hh23
2 files changed, 52 insertions, 1 deletions
diff --git a/paludis/util/fs_entry.cc b/paludis/util/fs_entry.cc
index 134e918..e9141a5 100644
--- a/paludis/util/fs_entry.cc
+++ b/paludis/util/fs_entry.cc
@@ -387,3 +387,33 @@ FSEntry::readlink() const
throw FSError("readlink '" + _path + "' failed: " + ::strerror(errno));
return buf;
}
+
+void
+FSEntry::chown(const uid_t owner, const gid_t group)
+{
+ if (0 != ::chown(_path.c_str(), owner, group))
+ throw FSError("chown '" + _path + "' failed: " + ::strerror(errno));
+}
+
+uid_t
+FSEntry::owner() const
+{
+ _stat();
+
+ if (! _exists)
+ throw FSError("Filesystem entry '" + _path + "' does not exist");
+
+ return _stat_info->st_uid;
+}
+
+gid_t
+FSEntry::group() const
+{
+ _stat();
+
+ if (! _exists)
+ throw FSError("Filesystem entry '" + _path + "' does not exist");
+
+ return _stat_info->st_gid;
+}
+
diff --git a/paludis/util/fs_entry.hh b/paludis/util/fs_entry.hh
index a2882b8..703d64e 100644
--- a/paludis/util/fs_entry.hh
+++ b/paludis/util/fs_entry.hh
@@ -241,7 +241,7 @@ namespace paludis
* \exception FSError If an error other than the directory already
* existing occurs.
*/
- bool mkdir(mode_t mode = 0755);
+ bool mkdir(const mode_t mode = 0755);
/**
* Try to unlink.
@@ -255,6 +255,27 @@ namespace paludis
bool unlink();
/**
+ * Change our permissions.
+ *
+ * \exception FSError If the chown failed.
+ */
+ void chown(const uid_t owner, const gid_t group);
+
+ /**
+ * Fetch our owner.
+ *
+ * \exception FSError If we don't exist or the stat call fails.
+ */
+ uid_t owner() const;
+
+ /**
+ * Fetch our group.
+ *
+ * \exception FSError If we don't exist or the stat call fails.
+ */
+ gid_t group() const;
+
+ /**
* Return the current working directory
*/
static FSEntry cwd();