From a38792f8d47c6e9577331f84dd834786d185b6e0 Mon Sep 17 00:00:00 2001 From: Roger Leigh Date: Sun, 28 Apr 2013 23:14:35 +0100 Subject: sbuild::chroot: Migrate custom to storage facet --- lib/sbuild/Makefile.am | 2 + lib/sbuild/chroot/custom.cc | 144 +---------------- lib/sbuild/chroot/custom.h | 75 --------- lib/sbuild/chroot/facet/custom.cc | 314 +++++++++++++++++--------------------- lib/sbuild/chroot/facet/custom.h | 237 ++++++++++++++-------------- 5 files changed, 269 insertions(+), 503 deletions(-) (limited to 'lib') 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 #include +#include #include #include #include @@ -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(); - } - - 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(); - } - - 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()->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() && - 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(get_facet()); - - 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 -#include #include -#include +#include #include +#include #include #include "format-detail.h" -#include "lock.h" #include #include -#include #include +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()); - 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()); - 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::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(); + } - 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(); - } + 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(); + } - 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()->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() && - get_session_purgeable()) - flags = SESSION_PURGE; + if (chroot.get_facet() && + 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(get_facet()); + bool is_session = static_cast(chroot.get_facet()); - 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 +#include 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 ptr; + + /// A shared_ptr to a const chroot facet object. + typedef std::shared_ptr 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: -- cgit v1.2.3