diff options
author | Roger Leigh <rleigh@debian.org> | 2013-04-27 22:52:14 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-05-04 17:17:17 +0100 |
commit | 176be0c58ce22af68b6661d1fe384ad8a59c5c9f (patch) | |
tree | 547d582f1796e58aec9fe96f183ed0ace3b94707 /lib | |
parent | f4ebdee7863c4c42756601641662bcd0c5fc0dd6 (diff) | |
download | schroot-176be0c58ce22af68b6661d1fe384ad8a59c5c9f.tar.gz |
sbuild::chroot: Migrate plain chroot type to storage facet
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbuild/Makefile.am | 2 | ||||
-rw-r--r-- | lib/sbuild/chroot/chroot.cc | 11 | ||||
-rw-r--r-- | lib/sbuild/chroot/chroot.h | 12 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/directory-base.h | 7 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/plain.cc | 117 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/plain.h | 87 | ||||
-rw-r--r-- | lib/sbuild/chroot/plain.cc | 36 | ||||
-rw-r--r-- | lib/sbuild/chroot/plain.h | 19 |
8 files changed, 109 insertions, 182 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index 69a10b35..85a120a2 100644 --- a/lib/sbuild/Makefile.am +++ b/lib/sbuild/Makefile.am @@ -29,6 +29,7 @@ lib_sbuild_public_h_sources = \ lib/sbuild/chroot/facet/directory-base.h \ lib/sbuild/chroot/facet/mountable.h \ lib/sbuild/chroot/facet/personality.h \ + lib/sbuild/chroot/facet/plain.h \ lib/sbuild/chroot/facet/session.h \ lib/sbuild/chroot/facet/session-clonable.h \ lib/sbuild/chroot/facet/source.h \ @@ -118,6 +119,7 @@ lib_sbuild_public_cc_sources = \ lib/sbuild/chroot/facet/directory-base.cc \ lib/sbuild/chroot/facet/mountable.cc \ lib/sbuild/chroot/facet/personality.cc \ + lib/sbuild/chroot/facet/plain.cc \ lib/sbuild/chroot/facet/session.cc \ lib/sbuild/chroot/facet/session-clonable.cc \ lib/sbuild/chroot/facet/source.cc \ diff --git a/lib/sbuild/chroot/chroot.cc b/lib/sbuild/chroot/chroot.cc index cdf2e470..2582cf16 100644 --- a/lib/sbuild/chroot/chroot.cc +++ b/lib/sbuild/chroot/chroot.cc @@ -38,6 +38,7 @@ #endif // SBUILD_FEATURE_BTRFSSNAP #include <sbuild/chroot/facet/facet.h> #include <sbuild/chroot/facet/personality.h> +#include <sbuild/chroot/facet/plain.h> #include <sbuild/chroot/facet/session.h> #include <sbuild/chroot/facet/session-clonable.h> #include <sbuild/chroot/facet/source.h> @@ -106,7 +107,6 @@ namespace sbuild environment_filter(SBUILD_DEFAULT_ENVIRONMENT_FILTER), mount_location(), original(true), - run_setup_scripts(true), script_config(), profile("default"), command_prefix(), @@ -136,7 +136,6 @@ namespace sbuild environment_filter(rhs.environment_filter), mount_location(rhs.mount_location), original(rhs.original), - run_setup_scripts(rhs.run_setup_scripts), script_config(rhs.script_config), profile(rhs.profile), command_prefix(rhs.command_prefix), @@ -387,13 +386,9 @@ namespace sbuild bool chroot::get_run_setup_scripts () const { - return this->run_setup_scripts; - } + facet::plain::const_ptr plain = get_facet<facet::plain>(); - void - chroot::set_run_setup_scripts (bool run_setup_scripts) - { - this->run_setup_scripts = run_setup_scripts; + return !static_cast<bool>(plain); } std::string const& diff --git a/lib/sbuild/chroot/chroot.h b/lib/sbuild/chroot/chroot.h index 7293de0f..e8c20951 100644 --- a/lib/sbuild/chroot/chroot.h +++ b/lib/sbuild/chroot/chroot.h @@ -404,16 +404,6 @@ namespace sbuild bool get_run_setup_scripts () const; - protected: - /** - * Set whether chroot setup scripts will be run. - * - * @param run_setup_scripts true if setup scripts will be run, - * otherwise false. - */ - void - set_run_setup_scripts (bool run_setup_scripts); - public: /** * Get the script configuration file for the chroot. This is a @@ -864,8 +854,6 @@ namespace sbuild std::string mount_location; /// Was the chroot automatically generated? bool original; - /// Run chroot setup scripts? - bool run_setup_scripts; /// Configuration of the setup and exec scripts. std::string script_config; /// Configuration profile for setup scripts (replaces script_config). diff --git a/lib/sbuild/chroot/facet/directory-base.h b/lib/sbuild/chroot/facet/directory-base.h index 0fbc5aec..e52366b8 100644 --- a/lib/sbuild/chroot/facet/directory-base.h +++ b/lib/sbuild/chroot/facet/directory-base.h @@ -58,10 +58,6 @@ namespace sbuild /// The destructor. virtual ~directory_base (); - protected: - void - set_chroot (chroot& chroot); - public: /** * Get the directory containing the chroot. @@ -79,9 +75,6 @@ namespace sbuild void set_directory (std::string const& directory); - virtual std::string - get_path () const; - virtual void setup_env (chroot const& chroot, environment& env) const; diff --git a/lib/sbuild/chroot/facet/plain.cc b/lib/sbuild/chroot/facet/plain.cc index 8ed06c7b..f97904ce 100644 --- a/lib/sbuild/chroot/facet/plain.cc +++ b/lib/sbuild/chroot/facet/plain.cc @@ -18,85 +18,74 @@ #include <config.h> -#include <sbuild/chroot/plain.h> +#include <sbuild/chroot/facet/plain.h> #include <sbuild/chroot/facet/session-clonable.h> #include "format-detail.h" -#include "lock.h" +#include "util.h" +#include <cassert> #include <cerrno> +#include <cstring> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/sysmacros.h> -#include <unistd.h> +#include <boost/format.hpp> +using boost::format; using namespace sbuild; namespace sbuild { namespace chroot { - - plain::plain (): - directory_base() - { - set_run_setup_scripts(false); - - remove_facet<facet::session_clonable>(); - } - - plain::~plain () - { - } - - chroot::ptr - plain::clone () const - { - return ptr(new plain(*this)); - } - - chroot::ptr - plain::clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const - { - return ptr(); - } - - chroot::ptr - plain::clone_source () const + namespace facet { - return ptr(); - } - std::string const& - plain::get_chroot_type () const - { - static const std::string type("plain"); + plain::plain (): + directory_base() + { + } + + plain::~plain () + { + } + + plain::plain (const plain& rhs): + directory_base(rhs) + { + } + + void + plain::set_chroot (chroot& chroot) + { + directory_base::set_chroot(chroot); + owner->remove_facet<session_clonable>(); + } + + std::string const& + plain::get_name () const + { + static const std::string name("plain"); + + return name; + } + + plain::ptr + plain::create () + { + return ptr(new plain()); + } + + facet::ptr + plain::clone () const + { + return ptr(new plain(*this)); + } + + std::string + plain::get_path () const + { + return get_directory(); + } - return type; } - - std::string - plain::get_path () const - { - return get_directory(); - } - - void - plain::setup_lock (setup_type type, - bool lock, - int status) - { - /* By default, plain chroots do no locking. */ - } - - chroot::session_flags - plain::get_session_flags (chroot const& chroot) const - { - return SESSION_NOFLAGS; - } - } } diff --git a/lib/sbuild/chroot/facet/plain.h b/lib/sbuild/chroot/facet/plain.h index 98bf2abd..70c938ed 100644 --- a/lib/sbuild/chroot/facet/plain.h +++ b/lib/sbuild/chroot/facet/plain.h @@ -16,67 +16,72 @@ * *********************************************************************/ -#ifndef SBUILD_CHROOT_PLAIN_H -#define SBUILD_CHROOT_PLAIN_H +#ifndef SBUILD_CHROOT_FACET_PLAIN_H +#define SBUILD_CHROOT_FACET_PLAIN_H -#include <sbuild/chroot/directory-base.h> +#include <sbuild/config.h> +#include <sbuild/chroot/facet/directory-base.h> namespace sbuild { namespace chroot { - - /** - * A chroot located in the filesystem (scripts disabled). - * - * This doesn't run any setup scripts and doesn't provide any - * session support. If you need any of these functions, the - * directory chroot type is more suited to your needs. - */ - class plain : public directory_base + namespace facet { - protected: - /// The constructor. - plain (); - friend class chroot; + /** + * A chroot stored on an unmounted block device. + * + * The device will be mounted on demand. + */ + class plain : public directory_base + { + public: + /// A shared_ptr to a chroot facet object. + typedef std::shared_ptr<plain> ptr; + + /// A shared_ptr to a const chroot facet object. + typedef std::shared_ptr<const plain> const_ptr; + + protected: + /// The constructor. + plain (); - public: - /// The destructor. - virtual ~plain (); + /// The copy constructor. + plain (const plain& rhs); - virtual chroot::ptr - clone () const; + void + set_chroot (chroot& chroot); - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; + friend class chroot; - virtual chroot::ptr - clone_source () const; + public: + /// The destructor. + virtual ~plain (); - virtual std::string - get_path () const; + virtual std::string const& + get_name () const; - virtual std::string const& - get_chroot_type () const; + /** + * Create a chroot facet. + * + * @returns a shared_ptr to the new chroot facet. + */ + static ptr + create (); - virtual session_flags - get_session_flags (chroot const& chroot) const; + virtual facet::ptr + clone () const; - protected: - virtual void - setup_lock (chroot::setup_type type, - bool lock, - int status); - }; + virtual std::string + get_path () const; + }; + } } } -#endif /* SBUILD_CHROOT_PLAIN_H */ +#endif /* SBUILD_CHROOT_FACET_PLAIN_H */ /* * Local Variables: diff --git a/lib/sbuild/chroot/plain.cc b/lib/sbuild/chroot/plain.cc index 8ed06c7b..2d61f546 100644 --- a/lib/sbuild/chroot/plain.cc +++ b/lib/sbuild/chroot/plain.cc @@ -19,7 +19,7 @@ #include <config.h> #include <sbuild/chroot/plain.h> -#include <sbuild/chroot/facet/session-clonable.h> +#include <sbuild/chroot/facet/plain.h> #include "format-detail.h" #include "lock.h" @@ -38,11 +38,9 @@ namespace sbuild { plain::plain (): - directory_base() + chroot() { - set_run_setup_scripts(false); - - remove_facet<facet::session_clonable>(); + add_facet(facet::plain::create()); } plain::~plain () @@ -70,33 +68,5 @@ namespace sbuild return ptr(); } - std::string const& - plain::get_chroot_type () const - { - static const std::string type("plain"); - - return type; - } - - std::string - plain::get_path () const - { - return get_directory(); - } - - void - plain::setup_lock (setup_type type, - bool lock, - int status) - { - /* By default, plain chroots do no locking. */ - } - - chroot::session_flags - plain::get_session_flags (chroot const& chroot) const - { - return SESSION_NOFLAGS; - } - } } diff --git a/lib/sbuild/chroot/plain.h b/lib/sbuild/chroot/plain.h index 98bf2abd..ad285411 100644 --- a/lib/sbuild/chroot/plain.h +++ b/lib/sbuild/chroot/plain.h @@ -19,7 +19,7 @@ #ifndef SBUILD_CHROOT_PLAIN_H #define SBUILD_CHROOT_PLAIN_H -#include <sbuild/chroot/directory-base.h> +#include <sbuild/chroot/chroot.h> namespace sbuild { @@ -33,7 +33,7 @@ namespace sbuild * session support. If you need any of these functions, the * directory chroot type is more suited to your needs. */ - class plain : public directory_base + class plain : public chroot { protected: /// The constructor. @@ -56,21 +56,6 @@ namespace sbuild virtual chroot::ptr clone_source () const; - - virtual std::string - get_path () const; - - virtual std::string const& - get_chroot_type () const; - - virtual session_flags - get_session_flags (chroot const& chroot) const; - - protected: - virtual void - setup_lock (chroot::setup_type type, - bool lock, - int status); }; } |