diff options
author | Roger Leigh <rleigh@debian.org> | 2013-04-27 18:29:02 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-05-04 17:17:17 +0100 |
commit | f4ebdee7863c4c42756601641662bcd0c5fc0dd6 (patch) | |
tree | caf8c552218859bd736012578af146a2176cd474 /lib | |
parent | 9aec47cdd14e894be28046046bf158a5febade8c (diff) | |
download | schroot-f4ebdee7863c4c42756601641662bcd0c5fc0dd6.tar.gz |
sbuild::chroot::facet: Add directory_base storage facet
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sbuild/Makefile.am | 2 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/directory-base.cc | 211 | ||||
-rw-r--r-- | lib/sbuild/chroot/facet/directory-base.h | 148 |
3 files changed, 179 insertions, 182 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index 76077383..69a10b35 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/facet.h \ + lib/sbuild/chroot/facet/directory-base.h \ lib/sbuild/chroot/facet/mountable.h \ lib/sbuild/chroot/facet/personality.h \ lib/sbuild/chroot/facet/session.h \ @@ -114,6 +115,7 @@ lib_sbuild_public_cc_sources = \ lib/sbuild/chroot/directory.cc \ lib/sbuild/chroot/directory-base.cc \ lib/sbuild/chroot/facet/facet.cc \ + lib/sbuild/chroot/facet/directory-base.cc \ lib/sbuild/chroot/facet/mountable.cc \ lib/sbuild/chroot/facet/personality.cc \ lib/sbuild/chroot/facet/session.cc \ diff --git a/lib/sbuild/chroot/facet/directory-base.cc b/lib/sbuild/chroot/facet/directory-base.cc index a876eb33..3be65c24 100644 --- a/lib/sbuild/chroot/facet/directory-base.cc +++ b/lib/sbuild/chroot/facet/directory-base.cc @@ -18,16 +18,14 @@ #include <config.h> -#include <sbuild/chroot/directory-base.h> -#include <sbuild/format-detail.h> -#include <sbuild/lock.h> +#include <sbuild/chroot/facet/directory-base.h> +#include "format-detail.h" +#include "lock.h" +#include "util.h" #include <cerrno> - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/sysmacros.h> -#include <unistd.h> +#include <cstring> +#include <iostream> using namespace sbuild; @@ -35,114 +33,101 @@ namespace sbuild { namespace chroot { - - directory_base::directory_base (): - chroot(), - directory() - { - } - - directory_base::directory_base (const directory_base& rhs): - chroot(rhs), - directory(rhs.directory) - { - } - - directory_base::directory_base (const chroot& rhs): - chroot(rhs), - directory() - { - } - - directory_base::~directory_base () + namespace facet { - } - - std::string const& - directory_base::get_directory () const - { - return this->directory; - } - void - directory_base::set_directory (std::string const& directory) - { - if (!is_absname(directory)) - throw chroot::error(directory, DIRECTORY_ABS); + directory_base::directory_base (): + storage(), + directory() + { + } + + directory_base::directory_base (const directory_base& rhs): + storage(rhs), + directory(rhs.directory) + { + } + + directory_base::~directory_base () + { + } + + std::string const& + directory_base::get_directory () const + { + return this->directory; + } + + void + directory_base::set_directory (std::string const& directory) + { + if (!is_absname(directory)) + throw chroot::error(directory, chroot::DIRECTORY_ABS); + + this->directory = directory; + } + + void + directory_base::setup_env (chroot const& chroot, + environment& env) const + { + env.add("CHROOT_DIRECTORY", get_directory()); + } + + void + directory_base::get_details (chroot const& chroot, + format_detail& detail) const + { + detail.add(_("Directory"), get_directory()); + } + + void + directory_base::get_used_keys (string_list& used_keys) const + { + used_keys.push_back("directory"); + used_keys.push_back("location"); + } + + void + directory_base::get_keyfile (chroot const& chroot, + keyfile& keyfile) const + { + keyfile::set_object_value(*this, &directory_base::get_directory, + keyfile, chroot.get_name(), "directory"); + } + + void + directory_base::set_keyfile (chroot& chroot, + keyfile const& keyfile) + { + // "directory" should be required, but we also accept "location" as + // an alternative (but deprecated) variant. Therefore, ensure by + // hand that one of them is defined, but not both. + + bool directory_key = keyfile.has_key(chroot.get_name(), "directory"); + bool location_key = keyfile.has_key(chroot.get_name(), "location"); + + keyfile::priority directory_priority = keyfile::PRIORITY_OPTIONAL; + keyfile::priority location_priority = keyfile::PRIORITY_OBSOLETE; + + if (!directory_key && !location_key) + throw keyfile::error(chroot.get_name(), keyfile::MISSING_KEY_NL, "directory"); + + // Using both keys is not allowed (which one is the correct one?), + // so force an exception to be thrown when reading the old location + // key. + if (directory_key && location_key) + location_priority = keyfile::PRIORITY_DISALLOWED; + + keyfile::get_object_value(*this, &directory_base::set_directory, + keyfile, chroot.get_name(), "directory", + directory_priority); + + keyfile::get_object_value(*this, &directory_base::set_directory, + keyfile, chroot.get_name(), "location", + location_priority); + } - this->directory = directory; } - - void - directory_base::setup_env (chroot const& chroot, - environment& env) const - { - chroot::setup_env(chroot, env); - - env.add("CHROOT_DIRECTORY", get_directory()); - } - - void - directory_base::get_details (chroot const& chroot, - format_detail& detail) const - { - chroot::get_details(chroot, detail); - - detail.add(_("Directory"), get_directory()); - } - - void - directory_base::get_used_keys (string_list& used_keys) const - { - chroot::get_used_keys(used_keys); - - used_keys.push_back("directory"); - used_keys.push_back("location"); - } - - void - directory_base::get_keyfile (chroot const& chroot, - keyfile& keyfile) const - { - chroot::get_keyfile(chroot, keyfile); - - keyfile::set_object_value(*this, &directory_base::get_directory, - keyfile, get_name(), "directory"); - } - - void - directory_base::set_keyfile (chroot& chroot, - keyfile const& keyfile) - { - chroot::set_keyfile(chroot, keyfile); - - // "directory" should be required, but we also accept "location" as - // an alternative (but deprecated) variant. Therefore, ensure by - // hand that one of them is defined, but not both. - - bool directory_key = keyfile.has_key(get_name(), "directory"); - bool location_key = keyfile.has_key(get_name(), "location"); - - keyfile::priority directory_priority = keyfile::PRIORITY_OPTIONAL; - keyfile::priority location_priority = keyfile::PRIORITY_OBSOLETE; - - if (!directory_key && !location_key) - throw keyfile::error(get_name(), keyfile::MISSING_KEY_NL, "directory"); - - // Using both keys is not allowed (which one is the correct one?), - // so force an exception to be thrown when reading the old location - // key. - if (directory_key && location_key) - location_priority = keyfile::PRIORITY_DISALLOWED; - - keyfile::get_object_value(*this, &directory_base::set_directory, - keyfile, get_name(), "directory", - directory_priority); - - keyfile::get_object_value(*this, &directory_base::set_directory, - keyfile, get_name(), "location", - location_priority); - } - } } diff --git a/lib/sbuild/chroot/facet/directory-base.h b/lib/sbuild/chroot/facet/directory-base.h index a9da7463..0fbc5aec 100644 --- a/lib/sbuild/chroot/facet/directory-base.h +++ b/lib/sbuild/chroot/facet/directory-base.h @@ -16,91 +16,101 @@ * *********************************************************************/ -#ifndef SBUILD_CHROOT_DIRECTORY_BASE_H -#define SBUILD_CHROOT_DIRECTORY_BASE_H +#ifndef SBUILD_CHROOT_FACET_DIRECTORY_BASE_H +#define SBUILD_CHROOT_FACET_DIRECTORY_BASE_H #include <sbuild/chroot/chroot.h> +#include <sbuild/chroot/facet/storage.h> namespace sbuild { namespace chroot { - - /** - * A base class for chroots located in a local directory. - * - * This class doesn't implement a chroot (get_chroot_type is not - * implemented). plain and directory chroots inherit from this - * class. - * - * Originally plain inherited from the directory chroot, but this - * had to be changed when union support was introduced. As plain - * chroots don't run any setup scripts and basically just call - * 'chroot' on a directory, they can't support union based sessions. - */ - class directory_base : public chroot::chroot + namespace facet { - protected: - /// The constructor. - directory_base (); - - /// The copy constructor. - directory_base (const directory_base& rhs); - - /// The copy constructor. - directory_base (const chroot& rhs); - - friend class chroot; - - public: - /// The destructor. - virtual ~directory_base (); /** - * Get the directory containing the chroot. + * A base class for block-device chroots. * - * @returns the location. - */ - std::string const& - get_directory () const; - - /** - * Set the directory containing the chroot. + * This class doesn't implement a chroot (get_chroot_type + * is not implemented). * - * @param directory the directory. + * Originally lvm-snapshot inherited from the block-device chroot, + * but this was changed when union support was introduced. This + * design prevents lvm-snapshot offering union based sessions. */ - void - set_directory (std::string const& directory); - - virtual void - setup_env (chroot const& chroot, - environment& env) const; - - protected: - 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: - /// The directory to use. - std::string directory; - }; - + class directory_base : public storage + { + public: + /// Exception type. + typedef chroot::error error; + + protected: + /// The constructor. + directory_base (); + + /// The copy constructor. + directory_base (const directory_base& rhs); + + friend class chroot; + + public: + /// The destructor. + virtual ~directory_base (); + + protected: + void + set_chroot (chroot& chroot); + + public: + /** + * Get the directory containing the chroot. + * + * @returns the location. + */ + std::string const& + get_directory () const; + + /** + * Set the directory containing the chroot. + * + * @param directory the directory. + */ + void + set_directory (std::string const& directory); + + virtual std::string + get_path () const; + + virtual void + setup_env (chroot const& chroot, + environment& env) const; + + protected: + 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); + + /// The directory to use. + std::string directory; + }; + + } } } -#endif /* SBUILD_CHROOT_DIRECTORY_BASE_H */ +#endif /* SBUILD_CHROOT_FACET_DIRECTORY_BASE_H */ /* * Local Variables: |