diff options
-rw-r--r-- | sbuild/sbuild-chroot-directory.cc | 13 | ||||
-rw-r--r-- | sbuild/sbuild-chroot-plain.cc | 96 | ||||
-rw-r--r-- | sbuild/sbuild-chroot-plain.h | 49 |
3 files changed, 156 insertions, 2 deletions
diff --git a/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc index 273bb760..b5631f3e 100644 --- a/sbuild/sbuild-chroot-directory.cc +++ b/sbuild/sbuild-chroot-directory.cc @@ -47,6 +47,19 @@ chroot_directory::clone () const return ptr(new chroot_directory(*this)); } +sbuild::chroot::ptr +chroot_directory::clone_source () const +{ + ptr clone; + + if (get_union_configured()) { + clone = ptr(new chroot_directory(*this)); + chroot_source::clone_source_setup(clone); + } + + return ptr(clone); +} + std::string const& chroot_directory::get_directory () const { diff --git a/sbuild/sbuild-chroot-plain.cc b/sbuild/sbuild-chroot-plain.cc index 7a59a80e..356d8467 100644 --- a/sbuild/sbuild-chroot-plain.cc +++ b/sbuild/sbuild-chroot-plain.cc @@ -48,9 +48,105 @@ chroot_plain::clone () const } std::string const& +chroot_plain::get_directory () const +{ + return this->directory; +} + +void +chroot_plain::set_directory (std::string const& directory) +{ + if (!is_absname(directory)) + throw chroot::error(directory, DIRECTORY_ABS); + + this->directory = directory; +} + +std::string const& chroot_plain::get_chroot_type () const { static const std::string type("plain"); return type; } + +std::string +chroot_plain::get_path () const +{ + return get_directory(); +} + +void +chroot_plain::setup_env (environment& env) +{ + chroot::setup_env(env); + + env.add("CHROOT_DIRECTORY", get_directory()); +} + +void +chroot_plain::setup_lock (chroot::setup_type type, + bool lock, + int status) +{ + /* By default, plain chroots do no locking. */ +} + +sbuild::chroot::session_flags +chroot_plain::get_session_flags () const +{ + return SESSION_NOFLAGS; +} + +void +chroot_plain::get_details (format_detail& detail) const +{ + chroot::get_details(detail); + + detail.add(_("Directory"), get_directory()); +} + +void +chroot_plain::get_keyfile (keyfile& keyfile) const +{ + chroot::get_keyfile(keyfile); + + keyfile::set_object_value(*this, &chroot_plain::get_directory, + keyfile, get_name(), "directory"); +} + +void +chroot_plain::set_keyfile (keyfile const& keyfile, + string_list& used_keys) +{ + chroot::set_keyfile(keyfile, used_keys); + + // "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_DEPRECATED; + + 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, &chroot_plain::set_directory, + keyfile, get_name(), "directory", + directory_priority); + used_keys.push_back("directory"); + + keyfile::get_object_value(*this, &chroot_plain::set_directory, + keyfile, get_name(), "location", + location_priority); + used_keys.push_back("location"); +} diff --git a/sbuild/sbuild-chroot-plain.h b/sbuild/sbuild-chroot-plain.h index adcbd22d..3d245cb1 100644 --- a/sbuild/sbuild-chroot-plain.h +++ b/sbuild/sbuild-chroot-plain.h @@ -19,7 +19,7 @@ #ifndef SBUILD_CHROOT_PLAIN_H #define SBUILD_CHROOT_PLAIN_H -#include <sbuild/sbuild-chroot-directory.h> +#include <sbuild/sbuild-chroot.h> namespace sbuild { @@ -27,7 +27,7 @@ namespace sbuild /** * A chroot located in the filesystem (mounts disabled). */ - class chroot_plain : public chroot_directory + class chroot_plain : virtual public chroot { protected: /// The constructor. @@ -42,8 +42,53 @@ namespace sbuild virtual chroot::ptr clone () const; + /** + * 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 std::string const& get_chroot_type () const; + + virtual void + setup_env (environment& env); + + virtual session_flags + get_session_flags () const; + + protected: + virtual void + setup_lock (chroot::setup_type type, + bool lock, + int status); + + virtual void + get_details (format_detail& detail) const; + + virtual void + get_keyfile (keyfile& keyfile) const; + + virtual void + set_keyfile (keyfile const& keyfile, + string_list& used_keys); + + private: + /// The directory to use. + std::string directory; }; } |