diff options
author | Roger Leigh <rleigh@debian.org> | 2013-04-07 19:51:40 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-04-09 22:36:44 +0100 |
commit | 1addd2e83281ccffd9624209f0f3f9d8197bd48c (patch) | |
tree | 09a2e5aabe2b7fbb5121fab2e9e15515d8563037 /lib | |
parent | 3cf9dcaf71590c5bdfb388adf95bb0dc88841bbf (diff) | |
download | schroot-1addd2e83281ccffd9624209f0f3f9d8197bd48c.tar.gz |
sbuild: Move chroot-custom to namespace chroot
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbuild/Makefile.am | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot-custom.cc | 224 | ||||
-rw-r--r-- | lib/sbuild/chroot-custom.h | 148 | ||||
-rw-r--r-- | lib/sbuild/chroot/chroot.cc | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot/custom.cc | 232 | ||||
-rw-r--r-- | lib/sbuild/chroot/custom.h | 151 |
6 files changed, 387 insertions, 376 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index 07de2197..b9534e4a 100644 --- a/lib/sbuild/Makefile.am +++ b/lib/sbuild/Makefile.am @@ -22,7 +22,7 @@ lib_sbuild_public_h_sources = \ lib/sbuild/auth.h \ lib/sbuild/auth-null.h \ lib/sbuild/chroot/chroot.h \ - lib/sbuild/chroot-custom.h \ + lib/sbuild/chroot/custom.h \ lib/sbuild/chroot/directory.h \ lib/sbuild/chroot/directory-base.h \ lib/sbuild/chroot-facet.h \ @@ -107,7 +107,7 @@ lib_sbuild_public_cc_sources = \ lib/sbuild/auth.cc \ lib/sbuild/auth-null.cc \ lib/sbuild/chroot/chroot.cc \ - lib/sbuild/chroot-custom.cc \ + lib/sbuild/chroot/custom.cc \ lib/sbuild/chroot/directory.cc \ lib/sbuild/chroot/directory-base.cc \ lib/sbuild/chroot-facet-mountable.cc \ diff --git a/lib/sbuild/chroot-custom.cc b/lib/sbuild/chroot-custom.cc deleted file mode 100644 index 51d452d0..00000000 --- a/lib/sbuild/chroot-custom.cc +++ /dev/null @@ -1,224 +0,0 @@ -/* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org> - * - * schroot is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * schroot is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - * - *********************************************************************/ - -#include <config.h> - -#include "chroot-custom.h" -#include "chroot-facet-session.h" -#include "chroot-facet-session-clonable.h" -#include "chroot-facet-source-clonable.h" -#include "format-detail.h" -#include "lock.h" - -#include <cassert> -#include <cerrno> -#include <cstring> - -#include <boost/format.hpp> - -using boost::format; -using namespace sbuild; - -chroot_custom::chroot_custom (): - chroot(), - purgeable(false) -{ -} - -chroot_custom::chroot_custom (const chroot_custom& rhs): - chroot(rhs), - purgeable(false) -{ -} - -chroot_custom::~chroot_custom () -{ -} - -chroot::chroot::ptr -chroot_custom::clone () const -{ - return ptr(new chroot_custom(*this)); -} - -chroot::chroot::ptr -chroot_custom::clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const -{ - chroot_facet_session_clonable::const_ptr psess - (get_facet<chroot_facet_session_clonable>()); - assert(psess); - - ptr session(new chroot_custom(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; -} - -chroot::chroot::ptr -chroot_custom::clone_source () const -{ - chroot_custom *clone_custom = new chroot_custom(*this); - ptr clone(clone_custom); - - chroot_facet_source_clonable::const_ptr psrc - (get_facet<chroot_facet_source_clonable>()); - assert(psrc); - - psrc->clone_source_setup(*this, clone); - - return clone; -} - -void -chroot_custom::set_session_cloneable (bool cloneable) -{ - if (cloneable) - add_facet(sbuild::chroot_facet_session_clonable::create()); - else - remove_facet<chroot_facet_session_clonable>(); -} - -void -chroot_custom::set_session_purgeable (bool purgeable) -{ - this->purgeable = purgeable; -} - -bool -chroot_custom::get_session_purgeable () const -{ - return this->purgeable; -} - -void -chroot_custom::set_source_cloneable (bool cloneable) -{ - if (cloneable) - add_facet(chroot_facet_source_clonable::create()); - else - remove_facet<chroot_facet_source_clonable>(); -} - -std::string -chroot_custom::get_path () const -{ - // TODO: Allow customisation? Or require use of mount location? - return get_mount_location(); -} - -void -chroot_custom::setup_env (chroot const& chroot, - environment& env) const -{ - chroot::setup_env(chroot, env); -} - -std::string const& -chroot_custom::get_chroot_type () const -{ - static const std::string type("custom"); - - return type; -} - -void -chroot_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); - } -} - -chroot::chroot::session_flags -chroot_custom::get_session_flags (chroot const& chroot) const -{ - session_flags flags = SESSION_NOFLAGS; - - // TODO: Only set if purge is set. - - if (chroot.get_facet<chroot_facet_session>() && - get_session_purgeable()) - flags = SESSION_PURGE; - - return flags; -} - -void -chroot_custom::get_details (chroot const& chroot, - format_detail& detail) const -{ - chroot::get_details(chroot, detail); -} - -void -chroot_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 -chroot_custom::get_keyfile (chroot const& chroot, - keyfile& keyfile) const -{ - chroot::get_keyfile(chroot, keyfile); - - keyfile::set_object_value(*this, - &chroot_custom::get_session_purgeable, - keyfile, get_name(), - "custom-session-purgeable"); -} - -void -chroot_custom::set_keyfile (chroot& chroot, - keyfile const& keyfile) -{ - chroot::set_keyfile(chroot, keyfile); - - bool session = static_cast<bool>(get_facet<chroot_facet_session>()); - - keyfile::get_object_value(*this, &chroot_custom::set_session_cloneable, - keyfile, get_name(), "custom-session-cloneable", - session ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_OPTIONAL); - - keyfile::get_object_value(*this, &chroot_custom::set_session_purgeable, - keyfile, get_name(), "custom-session-purgeable", - keyfile::PRIORITY_OPTIONAL); - - keyfile::get_object_value(*this, &chroot_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 deleted file mode 100644 index 913c87b0..00000000 --- a/lib/sbuild/chroot-custom.h +++ /dev/null @@ -1,148 +0,0 @@ -/* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org> - * - * schroot is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * schroot is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see - * <http://www.gnu.org/licenses/>. - * - *********************************************************************/ - -#ifndef SBUILD_CHROOT_CUSTOM_H -#define SBUILD_CHROOT_CUSTOM_H - -#include <sbuild/chroot/chroot.h> - -namespace sbuild -{ - - /** - * 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 chroot_custom : public chroot::chroot - { - protected: - /// The constructor. - chroot_custom (); - - /// The copy constructor. - chroot_custom (const chroot_custom& rhs); - - friend class chroot; - - public: - /// The destructor. - virtual ~chroot_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. - * - * @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; - }; - -} - -#endif /* SBUILD_CHROOT_CUSTOM_H */ - -/* - * Local Variables: - * mode:C++ - * End: - */ diff --git a/lib/sbuild/chroot/chroot.cc b/lib/sbuild/chroot/chroot.cc index 6450cdee..c64c05ef 100644 --- a/lib/sbuild/chroot/chroot.cc +++ b/lib/sbuild/chroot/chroot.cc @@ -22,7 +22,7 @@ #include <sbuild/chroot/config.h> #include <sbuild/chroot/directory.h> #include <sbuild/chroot/plain.h> -#include "chroot-custom.h" +#include <sbuild/chroot/custom.h> #include <sbuild/chroot/file.h> #ifdef SBUILD_FEATURE_BLOCKDEV #include <sbuild/chroot/block-device.h> @@ -170,7 +170,7 @@ namespace sbuild else if (type == "plain") new_chroot = new plain(); else if (type == "custom") - new_chroot = new chroot_custom(); + new_chroot = new custom(); else if (type == "file") new_chroot = new file(); #ifdef SBUILD_FEATURE_BLOCKDEV diff --git a/lib/sbuild/chroot/custom.cc b/lib/sbuild/chroot/custom.cc new file mode 100644 index 00000000..dc8f091a --- /dev/null +++ b/lib/sbuild/chroot/custom.cc @@ -0,0 +1,232 @@ +/* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org> + * + * schroot is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + * + *********************************************************************/ + +#include <config.h> + +#include <sbuild/chroot/custom.h> +#include "chroot-facet-session.h" +#include "chroot-facet-session-clonable.h" +#include "chroot-facet-source-clonable.h" +#include "format-detail.h" +#include "lock.h" + +#include <cassert> +#include <cerrno> +#include <cstring> + +#include <boost/format.hpp> + +using boost::format; +using namespace sbuild; + +namespace sbuild +{ + namespace chroot + { + + 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 + { + chroot_facet_session_clonable::const_ptr psess + (get_facet<chroot_facet_session_clonable>()); + assert(psess); + + ptr session(new custom(*this)); + psess->clone_session_setup(*this, session, session_id, alias, user, root); + + return session; + } + + chroot::chroot::ptr + custom::clone_source () const + { + custom *clone_custom = new custom(*this); + ptr clone(clone_custom); + + chroot_facet_source_clonable::const_ptr psrc + (get_facet<chroot_facet_source_clonable>()); + assert(psrc); + + psrc->clone_source_setup(*this, clone); + + return clone; + } + + void + custom::set_session_cloneable (bool cloneable) + { + if (cloneable) + add_facet(sbuild::chroot_facet_session_clonable::create()); + else + remove_facet<chroot_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(chroot_facet_source_clonable::create()); + else + remove_facet<chroot_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); + 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<chroot_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<chroot_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 new file mode 100644 index 00000000..a5b88c1a --- /dev/null +++ b/lib/sbuild/chroot/custom.h @@ -0,0 +1,151 @@ +/* Copyright © 2005-2013 Roger Leigh <rleigh@debian.org> + * + * schroot is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + * <http://www.gnu.org/licenses/>. + * + *********************************************************************/ + +#ifndef SBUILD_CHROOT_CUSTOM_H +#define SBUILD_CHROOT_CUSTOM_H + +#include <sbuild/chroot/chroot.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 + { + 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. + * + * @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; + }; + + } +} + +#endif /* SBUILD_CHROOT_CUSTOM_H */ + +/* + * Local Variables: + * mode:C++ + * End: + */ |