summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2013-04-28 23:14:35 +0100
committerRoger Leigh <rleigh@debian.org>2013-05-04 17:17:17 +0100
commita38792f8d47c6e9577331f84dd834786d185b6e0 (patch)
tree7cdc7c0da8ccba8e6bfc33c8fe2a0ca327f4f80e /lib
parentc19190106d8339b4a7760e7b3bdfb0e9354fc4a8 (diff)
downloadschroot-a38792f8d47c6e9577331f84dd834786d185b6e0.tar.gz
sbuild::chroot: Migrate custom to storage facet
Diffstat (limited to 'lib')
-rw-r--r--lib/sbuild/Makefile.am2
-rw-r--r--lib/sbuild/chroot/custom.cc144
-rw-r--r--lib/sbuild/chroot/custom.h75
-rw-r--r--lib/sbuild/chroot/facet/custom.cc314
-rw-r--r--lib/sbuild/chroot/facet/custom.h237
5 files changed, 269 insertions, 503 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am
index 3be12b47..a620b78f 100644
--- a/lib/sbuild/Makefile.am
+++ b/lib/sbuild/Makefile.am
@@ -26,6 +26,7 @@ lib_sbuild_public_h_sources = \
lib/sbuild/chroot/directory.h \
lib/sbuild/chroot/directory-base.h \
lib/sbuild/chroot/facet/btrfs-snapshot.cc \
+ lib/sbuild/chroot/facet/custom.h \
lib/sbuild/chroot/facet/directory.h \
lib/sbuild/chroot/facet/directory-base.h \
lib/sbuild/chroot/facet/facet.h \
@@ -121,6 +122,7 @@ lib_sbuild_public_cc_sources = \
lib/sbuild/chroot/directory.cc \
lib/sbuild/chroot/directory-base.cc \
lib/sbuild/chroot/facet/btrfs-snapshot.cc \
+ lib/sbuild/chroot/facet/custom.cc \
lib/sbuild/chroot/facet/directory.cc \
lib/sbuild/chroot/facet/directory-base.cc \
lib/sbuild/chroot/facet/facet.cc \
diff --git a/lib/sbuild/chroot/custom.cc b/lib/sbuild/chroot/custom.cc
index 22ce9b42..45000cf1 100644
--- a/lib/sbuild/chroot/custom.cc
+++ b/lib/sbuild/chroot/custom.cc
@@ -19,6 +19,7 @@
#include <config.h>
#include <sbuild/chroot/custom.h>
+#include <sbuild/chroot/facet/custom.h>
#include <sbuild/chroot/facet/session.h>
#include <sbuild/chroot/facet/session-clonable.h>
#include <sbuild/chroot/facet/source-clonable.h>
@@ -40,14 +41,13 @@ namespace sbuild
{
custom::custom ():
- chroot(),
- purgeable(false)
+ chroot()
{
+ add_facet(facet::custom::create());
}
custom::custom (const custom& rhs):
- chroot(rhs),
- purgeable(false)
+ chroot(rhs)
{
}
@@ -92,141 +92,5 @@ namespace sbuild
return clone;
}
- void
- custom::set_session_cloneable (bool cloneable)
- {
- if (cloneable)
- add_facet(facet::session_clonable::create());
- else
- remove_facet<facet::session_clonable>();
- }
-
- void
- custom::set_session_purgeable (bool purgeable)
- {
- this->purgeable = purgeable;
- }
-
- bool
- custom::get_session_purgeable () const
- {
- return this->purgeable;
- }
-
- void
- custom::set_source_cloneable (bool cloneable)
- {
- if (cloneable)
- add_facet(facet::source_clonable::create());
- else
- remove_facet<facet::source_clonable>();
- }
-
- std::string
- custom::get_path () const
- {
- // TODO: Allow customisation? Or require use of mount location?
- return get_mount_location();
- }
-
- void
- custom::setup_env (chroot const& chroot,
- environment& env) const
- {
- chroot::setup_env(chroot, env);
- }
-
- std::string const&
- custom::get_chroot_type () const
- {
- static const std::string type("custom");
-
- return type;
- }
-
- void
- custom::setup_lock (chroot::setup_type type,
- bool lock,
- int status)
- {
- /* By default, custom chroots do no locking. */
- /* Create or unlink session information. */
- if ((type == SETUP_START && lock == true) ||
- (type == SETUP_STOP && lock == false && status == 0))
- {
-
- bool start = (type == SETUP_START);
- get_facet_strict<facet::session>()->setup_session_info(start);
- }
- }
-
- chroot::chroot::session_flags
- custom::get_session_flags (chroot const& chroot) const
- {
- session_flags flags = SESSION_NOFLAGS;
-
- // TODO: Only set if purge is set.
-
- if (chroot.get_facet<facet::session>() &&
- get_session_purgeable())
- flags = SESSION_PURGE;
-
- return flags;
- }
-
- void
- custom::get_details (chroot const& chroot,
- format_detail& detail) const
- {
- chroot::get_details(chroot, detail);
- }
-
- void
- custom::get_used_keys (string_list& used_keys) const
- {
- chroot::get_used_keys(used_keys);
-
- used_keys.push_back("custom-cloneable");
- used_keys.push_back("custom-purgeable");
- used_keys.push_back("custom-source-cloneable");
- }
-
- void
- custom::get_keyfile (chroot const& chroot,
- keyfile& keyfile) const
- {
- chroot::get_keyfile(chroot, keyfile);
-
- keyfile::set_object_value(*this,
- &custom::get_session_purgeable,
- keyfile, get_name(),
- "custom-session-purgeable");
- }
-
- void
- custom::set_keyfile (chroot& chroot,
- keyfile const& keyfile)
- {
- chroot::set_keyfile(chroot, keyfile);
-
- bool session = static_cast<bool>(get_facet<facet::session>());
-
- keyfile::get_object_value(*this, &custom::set_session_cloneable,
- keyfile, get_name(), "custom-session-cloneable",
- session ?
- keyfile::PRIORITY_DISALLOWED :
- keyfile::PRIORITY_OPTIONAL);
-
- keyfile::get_object_value(*this, &custom::set_session_purgeable,
- keyfile, get_name(), "custom-session-purgeable",
- keyfile::PRIORITY_OPTIONAL);
-
- keyfile::get_object_value(*this, &custom::set_source_cloneable,
- keyfile, get_name(), "custom-source-cloneable",
- session ?
- keyfile::PRIORITY_DISALLOWED :
- keyfile::PRIORITY_OPTIONAL);
- }
-
}
}
diff --git a/lib/sbuild/chroot/custom.h b/lib/sbuild/chroot/custom.h
index a5b88c1a..0afb81ef 100644
--- a/lib/sbuild/chroot/custom.h
+++ b/lib/sbuild/chroot/custom.h
@@ -62,81 +62,6 @@ namespace sbuild
virtual chroot::ptr
clone_source () const;
-
- /**
- * Enable or disable cloning of the chroot session. This simply
- * creates or removes the chroot_facet_session_cloneable facet,
- * hence there is no companion get method.
- *
- * @param cloneable true if cloneable, false if not.
- */
- void
- set_session_cloneable (bool cloneable);
-
- /**
- * Enable or disable purging of the chroot session. Note that
- * this is only usable if the chroot supports session cloning,
- * otherwise this does nothing.
- *
- * @param purgeable true if purgeable, false if not.
- */
- void
- set_session_purgeable (bool purgeable);
-
- /**
- * Get status of chroot session purging.
- *
- * @returns true if purgeable, false if not.
- */
- bool
- get_session_purgeable () const;
-
- /**
- * Enable or disable cloning of the source chroot. This simply
- * creates or removes the chroot_facet_source_cloneable facet,
- * hence there is no companion get method.
- *
- * @param cloneable true if source cloneable, false if not.
- */
- void
- set_source_cloneable (bool cloneable);
-
- virtual void
- setup_env (chroot const& chroot,
- environment& env) const;
-
- virtual std::string const&
- get_chroot_type () const;
-
- std::string
- get_path () const;
-
- virtual session_flags
- get_session_flags (chroot const& chroot) const;
-
- protected:
- virtual void
- setup_lock (chroot::setup_type type,
- bool lock,
- int status);
-
- virtual void
- get_details (chroot const& chroot,
- format_detail& detail) const;
-
- virtual void
- get_used_keys (string_list& used_keys) const;
-
- virtual void
- get_keyfile (chroot const& chroot,
- keyfile& keyfile) const;
-
- virtual void
- set_keyfile (chroot& chroot,
- keyfile const& keyfile);
-
- private:
- bool purgeable;
};
}
diff --git a/lib/sbuild/chroot/facet/custom.cc b/lib/sbuild/chroot/facet/custom.cc
index 1b0e45dd..43f44f19 100644
--- a/lib/sbuild/chroot/facet/custom.cc
+++ b/lib/sbuild/chroot/facet/custom.cc
@@ -18,20 +18,19 @@
#include <config.h>
-#include <sbuild/chroot/custom.h>
#include <sbuild/chroot/facet/factory.h>
-#include <sbuild/chroot/facet/session.h>
+#include <sbuild/chroot/facet/mountable.h>
#include <sbuild/chroot/facet/session-clonable.h>
+#include <sbuild/chroot/facet/session.h>
#include <sbuild/chroot/facet/source-clonable.h>
#include "format-detail.h"
-#include "lock.h"
#include <cassert>
#include <cerrno>
-#include <cstring>
#include <boost/format.hpp>
+using std::endl;
using boost::format;
using namespace sbuild;
@@ -39,209 +38,172 @@ namespace sbuild
{
namespace chroot
{
+ namespace facet
+ {
- namespace
+ custom::custom ():
+ storage(),
+ purgeable(false)
{
-
- factory::facet_info custom_info =
- {
- "custom",
- N_("Support for ‘custom’ chroots"),
- []() -> facet::ptr { return custom::create(); }
- };
-
- factory custom_register(custom_info);
-
}
- custom::custom ():
- chroot(),
- purgeable(false)
- {
- }
-
- custom::custom (const custom& rhs):
- chroot(rhs),
- purgeable(false)
- {
- }
-
- custom::~custom ()
- {
- }
-
- chroot::chroot::ptr
- custom::clone () const
- {
- return ptr(new custom(*this));
- }
-
- chroot::chroot::ptr
- custom::clone_session (std::string const& session_id,
- std::string const& alias,
- std::string const& user,
- bool root) const
- {
- facet::session_clonable::const_ptr psess
- (get_facet<facet::session_clonable>());
- assert(psess);
-
- ptr session(new custom(*this));
- psess->clone_session_setup(*this, session, session_id, alias, user, root);
-
- return session;
- }
+ custom::custom (const custom& rhs):
+ storage(rhs),
+ purgeable(rhs.purgeable)
+ {
+ }
- chroot::chroot::ptr
- custom::clone_source () const
- {
- custom *clone_custom = new custom(*this);
- ptr clone(clone_custom);
+ custom::~custom ()
+ {
+ }
- facet::source_clonable::const_ptr psrc
- (get_facet<facet::source_clonable>());
- assert(psrc);
+ std::string const&
+ custom::get_name () const
+ {
+ static const std::string name("custom");
- psrc->clone_source_setup(*this, clone);
+ return name;
+ }
- return clone;
- }
+ custom::ptr
+ custom::create ()
+ {
+ return ptr(new custom());
+ }
- void
- custom::set_session_cloneable (bool cloneable)
- {
- if (cloneable)
- add_facet(facet::session_clonable::create());
- else
- remove_facet<facet::session_clonable>();
- }
+ facet::ptr
+ custom::clone () const
+ {
+ return ptr(new custom(*this));
+ }
- void
- custom::set_session_purgeable (bool purgeable)
- {
- this->purgeable = purgeable;
- }
+ void
+ custom::set_session_cloneable (bool cloneable)
+ {
+ if (cloneable)
+ owner->add_facet(session_clonable::create());
+ else
+ owner->remove_facet<session_clonable>();
+ }
- bool
- custom::get_session_purgeable () const
- {
- return this->purgeable;
- }
+ void
+ custom::set_session_purgeable (bool purgeable)
+ {
+ this->purgeable = purgeable;
+ }
- void
- custom::set_source_cloneable (bool cloneable)
- {
- if (cloneable)
- add_facet(facet::source_clonable::create());
- else
- remove_facet<facet::source_clonable>();
- }
+ bool
+ custom::get_session_purgeable () const
+ {
+ return this->purgeable;
+ }
- std::string
- custom::get_path () const
- {
- // TODO: Allow customisation? Or require use of mount location?
- return get_mount_location();
- }
+ void
+ custom::set_source_cloneable (bool cloneable)
+ {
+ if (cloneable)
+ owner->add_facet(source_clonable::create());
+ else
+ owner->remove_facet<source_clonable>();
+ }
- void
- custom::setup_env (chroot const& chroot,
- environment& env) const
- {
- chroot::setup_env(chroot, env);
- }
+ std::string
+ custom::get_path () const
+ {
+ // TODO: Allow customisation? Or require use of mount location?
+ return owner->get_mount_location();
+ }
- std::string const&
- custom::get_chroot_type () const
- {
- static const std::string type("custom");
+ void
+ custom::setup_env (chroot const& chroot,
+ environment& env) const
+ {
+ storage::setup_env(chroot, env);
+ }
- return type;
- }
+ void
+ custom::setup_lock (chroot::setup_type type,
+ bool lock,
+ int status)
+ {
+ /* By default, custom chroots do no locking. */
+ /* Create or unlink session information. */
+ if ((type == chroot::SETUP_START && lock == true) ||
+ (type == chroot::SETUP_STOP && lock == false && status == 0))
+ {
- void
- custom::setup_lock (chroot::setup_type type,
- bool lock,
- int status)
- {
- /* By default, custom chroots do no locking. */
- /* Create or unlink session information. */
- if ((type == SETUP_START && lock == true) ||
- (type == SETUP_STOP && lock == false && status == 0))
- {
-
- bool start = (type == SETUP_START);
- setup_session_info(start);
- }
- }
+ bool start = (type == chroot::SETUP_START);
+ owner->get_facet_strict<session>()->setup_session_info(start);
+ }
+ }
- chroot::chroot::session_flags
- custom::get_session_flags (chroot const& chroot) const
- {
- session_flags flags = SESSION_NOFLAGS;
+ chroot::session_flags
+ custom::get_session_flags (chroot const& chroot) const
+ {
+ chroot::session_flags flags = chroot::SESSION_NOFLAGS;
- // TODO: Only set if purge is set.
+ // TODO: Only set if purge is set.
- if (chroot.get_facet<facet::session>() &&
- get_session_purgeable())
- flags = SESSION_PURGE;
+ if (chroot.get_facet<session>() &&
+ get_session_purgeable())
+ flags = chroot::SESSION_PURGE;
- return flags;
- }
+ return flags;
+ }
- void
- custom::get_details (chroot const& chroot,
- format_detail& detail) const
- {
- chroot::get_details(chroot, detail);
- }
+ void
+ custom::get_details (chroot const& chroot,
+ format_detail& detail) const
+ {
+ storage::get_details(chroot, detail);
+ }
- void
- custom::get_used_keys (string_list& used_keys) const
- {
- chroot::get_used_keys(used_keys);
+ void
+ custom::get_used_keys (string_list& used_keys) const
+ {
+ storage::get_used_keys(used_keys);
- used_keys.push_back("custom-cloneable");
- used_keys.push_back("custom-purgeable");
- used_keys.push_back("custom-source-cloneable");
- }
+ used_keys.push_back("custom-cloneable");
+ used_keys.push_back("custom-purgeable");
+ used_keys.push_back("custom-source-cloneable");
+ }
- void
- custom::get_keyfile (chroot const& chroot,
- keyfile& keyfile) const
- {
- chroot::get_keyfile(chroot, keyfile);
+ void
+ custom::get_keyfile (chroot const& chroot,
+ keyfile& keyfile) const
+ {
+ storage::get_keyfile(chroot, keyfile);
- keyfile::set_object_value(*this,
- &custom::get_session_purgeable,
- keyfile, get_name(),
- "custom-session-purgeable");
- }
+ keyfile::set_object_value(*this,
+ &custom::get_session_purgeable,
+ keyfile, chroot.get_name(),
+ "custom-session-purgeable");
+ }
- void
- custom::set_keyfile (chroot& chroot,
- keyfile const& keyfile)
- {
- chroot::set_keyfile(chroot, keyfile);
+ void
+ custom::set_keyfile (chroot& chroot,
+ keyfile const& keyfile)
+ {
+ storage::set_keyfile(chroot, keyfile);
- bool session = static_cast<bool>(get_facet<facet::session>());
+ bool is_session = static_cast<bool>(chroot.get_facet<session>());
- keyfile::get_object_value(*this, &custom::set_session_cloneable,
- keyfile, get_name(), "custom-session-cloneable",
- session ?
- keyfile::PRIORITY_DISALLOWED :
- keyfile::PRIORITY_OPTIONAL);
+ keyfile::get_object_value(*this, &custom::set_session_cloneable,
+ keyfile, chroot.get_name(), "custom-session-cloneable",
+ is_session ?
+ keyfile::PRIORITY_DISALLOWED :
+ keyfile::PRIORITY_OPTIONAL);
- keyfile::get_object_value(*this, &custom::set_session_purgeable,
- keyfile, get_name(), "custom-session-purgeable",
- keyfile::PRIORITY_OPTIONAL);
+ keyfile::get_object_value(*this, &custom::set_session_purgeable,
+ keyfile, chroot.get_name(), "custom-session-purgeable",
+ keyfile::PRIORITY_OPTIONAL);
- keyfile::get_object_value(*this, &custom::set_source_cloneable,
- keyfile, get_name(), "custom-source-cloneable",
- session ?
- keyfile::PRIORITY_DISALLOWED :
- keyfile::PRIORITY_OPTIONAL);
+ keyfile::get_object_value(*this, &custom::set_source_cloneable,
+ keyfile, chroot.get_name(), "custom-source-cloneable",
+ is_session ?
+ keyfile::PRIORITY_DISALLOWED :
+ keyfile::PRIORITY_OPTIONAL);
+ }
}
-
}
}
diff --git a/lib/sbuild/chroot/facet/custom.h b/lib/sbuild/chroot/facet/custom.h
index a5b88c1a..6f3b9272 100644
--- a/lib/sbuild/chroot/facet/custom.h
+++ b/lib/sbuild/chroot/facet/custom.h
@@ -16,133 +16,146 @@
*
*********************************************************************/
-#ifndef SBUILD_CHROOT_CUSTOM_H
-#define SBUILD_CHROOT_CUSTOM_H
+#ifndef SBUILD_CHROOT_FACET_CUSTOM_H
+#define SBUILD_CHROOT_FACET_CUSTOM_H
#include <sbuild/chroot/chroot.h>
+#include <sbuild/chroot/facet/storage.h>
namespace sbuild
{
namespace chroot
{
-
- /**
- * A chroot stored with custom parameters.
- *
- * This chroot specifies no behaviour or policy. It is entirely
- * configured using user options and setup scripts. The intent is
- * to permit the prototyping of and experimentation with new chroot
- * types without requiring a "full" class definition and associated
- * infrastructural work. It also makes schroot extensible without
- * requiring any C++ coding.
- */
- class custom : public chroot
+ namespace facet
{
- protected:
- /// The constructor.
- custom ();
-
- /// The copy constructor.
- custom (const custom& rhs);
-
- friend class chroot;
-
- public:
- /// The destructor.
- virtual ~custom ();
-
- virtual chroot::ptr
- clone () const;
-
- virtual chroot::ptr
- clone_session (std::string const& session_id,
- std::string const& alias,
- std::string const& user,
- bool root) const;
-
- virtual chroot::ptr
- clone_source () const;
-
- /**
- * Enable or disable cloning of the chroot session. This simply
- * creates or removes the chroot_facet_session_cloneable facet,
- * hence there is no companion get method.
- *
- * @param cloneable true if cloneable, false if not.
- */
- void
- set_session_cloneable (bool cloneable);
-
- /**
- * Enable or disable purging of the chroot session. Note that
- * this is only usable if the chroot supports session cloning,
- * otherwise this does nothing.
- *
- * @param purgeable true if purgeable, false if not.
- */
- void
- set_session_purgeable (bool purgeable);
/**
- * Get status of chroot session purging.
+ * A chroot stored with custom parameters.
*
- * @returns true if purgeable, false if not.
+ * This chroot specifies no behaviour or policy. It is entirely
+ * configured using user options and setup scripts. The intent is
+ * to permit the prototyping of and experimentation with new chroot
+ * types without requiring a "full" class definition and associated
+ * infrastructural work. It also makes schroot extensible without
+ * requiring any C++ coding.
*/
- bool
- get_session_purgeable () const;
-
- /**
- * Enable or disable cloning of the source chroot. This simply
- * creates or removes the chroot_facet_source_cloneable facet,
- * hence there is no companion get method.
- *
- * @param cloneable true if source cloneable, false if not.
- */
- void
- set_source_cloneable (bool cloneable);
-
- virtual void
- setup_env (chroot const& chroot,
- environment& env) const;
-
- virtual std::string const&
- get_chroot_type () const;
-
- std::string
- get_path () const;
-
- virtual session_flags
- get_session_flags (chroot const& chroot) const;
-
- protected:
- virtual void
- setup_lock (chroot::setup_type type,
- bool lock,
- int status);
-
- virtual void
- get_details (chroot const& chroot,
- format_detail& detail) const;
-
- virtual void
- get_used_keys (string_list& used_keys) const;
-
- virtual void
- get_keyfile (chroot const& chroot,
- keyfile& keyfile) const;
-
- virtual void
- set_keyfile (chroot& chroot,
- keyfile const& keyfile);
-
- private:
- bool purgeable;
- };
-
+ class custom : public storage
+ {
+ public:
+ /// Exception type.
+ typedef chroot::error error;
+
+ /// A shared_ptr to a chroot facet object.
+ typedef std::shared_ptr<custom> ptr;
+
+ /// A shared_ptr to a const chroot facet object.
+ typedef std::shared_ptr<const custom> const_ptr;
+
+ protected:
+ /// The constructor.
+ custom ();
+
+ /// The copy constructor.
+ custom (const custom& rhs);
+
+ friend class chroot;
+
+ public:
+ /// The destructor.
+ virtual ~custom ();
+
+ virtual std::string const&
+ get_name () const;
+
+ /**
+ * Create a chroot facet.
+ *
+ * @returns a shared_ptr to the new chroot facet.
+ */
+ static ptr
+ create ();
+
+ facet::ptr
+ clone () const;
+
+ /**
+ * Enable or disable cloning of the chroot session. This simply
+ * creates or removes the chroot_facet_session_cloneable facet,
+ * hence there is no companion get method.
+ *
+ * @param cloneable true if cloneable, false if not.
+ */
+ void
+ set_session_cloneable (bool cloneable);
+
+ /**
+ * Enable or disable purging of the chroot session. Note that
+ * this is only usable if the chroot supports session cloning,
+ * otherwise this does nothing.
+ *
+ * @param purgeable true if purgeable, false if not.
+ */
+ void
+ set_session_purgeable (bool purgeable);
+
+ /**
+ * Get status of chroot session purging.
+ *
+ * @returns true if purgeable, false if not.
+ */
+ bool
+ get_session_purgeable () const;
+
+ /**
+ * Enable or disable cloning of the source chroot. This simply
+ * creates or removes the chroot_facet_source_cloneable facet,
+ * hence there is no companion get method.
+ *
+ * @param cloneable true if source cloneable, false if not.
+ */
+ void
+ set_source_cloneable (bool cloneable);
+
+ virtual void
+ setup_env (chroot const& chroot,
+ environment& env) const;
+
+ std::string
+ get_path () const;
+
+ virtual chroot::session_flags
+ get_session_flags (chroot const& chroot) const;
+
+ protected:
+ virtual void
+ setup_lock (chroot::setup_type type,
+ bool lock,
+ int status);
+
+ virtual void
+ get_details (chroot const& chroot,
+ format_detail& detail) const;
+
+ virtual void
+ get_used_keys (string_list& used_keys) const;
+
+ virtual void
+ get_keyfile (chroot const& chroot,
+ keyfile& keyfile) const;
+
+ virtual void
+ set_keyfile (chroot& chroot,
+ keyfile const& keyfile);
+
+ private:
+ bool purgeable;
+ };
+
+ }
}
}
-#endif /* SBUILD_CHROOT_CUSTOM_H */
+#endif /* SBUILD_CHROOT_FACET_CUSTOM_H */
/*
* Local Variables: