sbuild
1.6.10
|
Chroot configuration. More...
#include <sbuild-chroot-config.h>
Public Types | |
enum | error_code { ALIAS_EXIST, CHROOT_NOTFOUND, CHROOTS_NOTFOUND, CHROOT_EXIST, FILE_NOTREG, FILE_OPEN, FILE_OWNER, FILE_PERMS, NAME_INVALID, NAMESPACE_NOTFOUND } |
Error codes. More... | |
typedef std::vector< chroot::ptr > | chroot_list |
A list of chroots. | |
typedef std::map< std::string, std::string > | string_map |
A map between key-value string pairs. | |
typedef std::map< std::string, chroot::ptr > | chroot_map |
A map between a chroot name and a chroot object. | |
typedef std::map< std::string, chroot_map > | chroot_namespace_map |
A map between a chroot namespace and a chroot map object. | |
typedef custom_error< error_code > | error |
Exception type. | |
typedef std::shared_ptr< chroot_config > | ptr |
A shared_ptr to a chroot_config object. | |
Public Member Functions | |
chroot_config () | |
The constructor. | |
chroot_config (std::string const &chroot_namespace, std::string const &file) | |
The constructor. More... | |
virtual | ~chroot_config () |
The destructor. | |
void | add (std::string const &chroot_namespace, std::string const &location) |
Add a configuration file or directory. More... | |
chroot_list | get_chroots (std::string const &chroot_namespace) const |
Get a list of available chroots. More... | |
const chroot::ptr | find_chroot (std::string const &name) const |
Find a chroot by its name. More... | |
const chroot::ptr | find_chroot (std::string const &namespace_hint, std::string const &name) const |
Find a chroot by its name. More... | |
const sbuild::chroot::ptr | find_chroot_in_namespace (std::string const &chroot_namespace, std::string const &name) const |
Find a chroot by its name in a specific namespace. More... | |
const chroot::ptr | find_alias (std::string const &namespace_hint, std::string const &name) const |
Find a chroot by its name or an alias. More... | |
std::string | lookup_alias (std::string const &namespace_hint, std::string const &name) const |
Find the chroot name referred to by an alias. More... | |
string_list | get_chroot_list (std::string const &chroot_namespace) const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order. More... | |
string_list | get_alias_list (std::string const &chroot_namespace) const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order. More... | |
void | print_chroot_list_simple (std::ostream &stream) const |
Print a single line of all the available chroots to the specified stream. More... | |
chroot_map | validate_chroots (std::string const &namespace_hint, string_list const &chroots) const |
Check that all the chroots specified exist. More... | |
Static Public Member Functions | |
static void | get_namespace (std::string const &name, std::string &chroot_namespace, std::string &chroot_name) |
Split a chroot name into a namespace and name. More... | |
Static Public Attributes | |
static const std::string | namespace_separator |
Namespace separating character. | |
Protected Member Functions | |
void | add (std::string const &chroot_namespace, chroot::ptr &chroot, keyfile const &kconfig) |
Add a chroot. More... | |
chroot_map & | find_namespace (std::string const &chroot_namespace) |
Find a chroot namespace. More... | |
chroot_map const & | find_namespace (std::string const &chroot_namespace) const |
Find a chroot namespace. More... | |
virtual void | parse_data (std::string const &chroot_namespace, std::istream &stream) |
Parse a loaded configuration file. More... | |
virtual void | load_keyfile (std::string const &chroot_namespace, keyfile &kconfig) |
Load a keyfile. More... | |
Protected Attributes | |
chroot_namespace_map | namespaces |
A list of chroots (name->chroot mapping). | |
string_map | aliases |
A list of aliases (alias->name mapping). | |
Private Member Functions | |
void | add_config_file (std::string const &chroot_namespace, std::string const &file) |
Add a configuration file. More... | |
void | add_config_directory (std::string const &chroot_namespace, std::string const &dir) |
Add a configuration directory. More... | |
void | load_data (std::string const &chroot_namespace, std::string const &file) |
Load a configuration file. More... | |
Chroot configuration.
This class holds the configuration details from the configuration file. Conceptually, it's an opaque container of chroot objects.
Methods are provided to query the available chroots and find specific chroots.
Error codes.
chroot_config::chroot_config | ( | std::string const & | chroot_namespace, |
std::string const & | file | ||
) |
The constructor.
chroot_namespace | the namespace to use for initialised configuration. |
file | initialise using a configuration file or a whole directory containing configuration files. |
References add(), and namespaces.
void chroot_config::add | ( | std::string const & | chroot_namespace, |
std::string const & | location | ||
) |
Add a configuration file or directory.
The configuration file or directory specified will be loaded.
chroot_namespace | the namespace to use for initialised configuration. |
location | initialise using a configuration file or a whole directory containing configuration files. |
References add_config_directory(), and add_config_file().
Referenced by chroot_config(), and load_keyfile().
|
protected |
Add a chroot.
The lists of chroots and aliases will be updated. If a chroot or alias by the same name exists, the chroot will not be added, and a warning will be logged. Af any of the aliases already exist, a warning will be logged, and the alias will not be added.
chroot_namespace | the namespace to use for the chroot. |
chroot | the chroot to add. |
kconfig | the chroot configuration. |
References sbuild::_(), ALIAS_EXIST, aliases, CHROOT_EXIST, find_namespace(), sbuild::basic_keyfile< K, P >::get_line(), sbuild::log_exception_warning(), namespace_separator, sbuild::keyfile_base::PASSTHROUGH_G, sbuild::keyfile_base::PASSTHROUGH_GK, sbuild::keyfile_base::PASSTHROUGH_LG, sbuild::keyfile_base::PASSTHROUGH_LGK, and sbuild::error_base::set_reason().
|
private |
Add a configuration directory.
The configuration files in the directory specified will all be loaded.
chroot_namespace | the namespace to use for initialised configuration. |
dir | the directory containing the files to load. |
References sbuild::DEBUG_NOTICE, FILE_NOTREG, sbuild::stat::is_regular(), sbuild::is_valid_sessionname(), load_data(), sbuild::log_debug(), and sbuild::log_exception_warning().
Referenced by add().
|
private |
Add a configuration file.
The configuration file specified will be loaded.
chroot_namespace | the namespace to use for initialised configuration. |
file | the file to load. |
References sbuild::DEBUG_NOTICE, load_data(), and sbuild::log_debug().
Referenced by add().
const sbuild::chroot::ptr chroot_config::find_alias | ( | std::string const & | namespace_hint, |
std::string const & | name | ||
) | const |
Find a chroot by its name or an alias.
namespace_hint | the namespace to use if non was explicitly specified. |
name | the chroot name or alias. |
References aliases, sbuild::DEBUG_NOTICE, find_chroot(), get_namespace(), sbuild::log_debug(), and namespace_separator.
Referenced by validate_chroots().
const sbuild::chroot::ptr chroot_config::find_chroot | ( | std::string const & | name | ) | const |
Find a chroot by its name.
The name must be fully qualified with a namespace.
name | the chroot name |
References find_chroot_in_namespace(), and get_namespace().
Referenced by find_alias().
const sbuild::chroot::ptr chroot_config::find_chroot | ( | std::string const & | namespace_hint, |
std::string const & | name | ||
) | const |
Find a chroot by its name.
namespace_hint | the namespace to use if non was explicitly specified. |
name | the chroot name |
References find_chroot_in_namespace(), and get_namespace().
const sbuild::chroot::ptr chroot_config::find_chroot_in_namespace | ( | std::string const & | chroot_namespace, |
std::string const & | name | ||
) | const |
Find a chroot by its name in a specific namespace.
chroot_namespace | the namespace to search. |
name | the chroot name |
References sbuild::DEBUG_NOTICE, find_namespace(), and sbuild::log_debug().
Referenced by find_chroot().
|
protected |
Find a chroot namespace.
If the namespace is not found, and exception will be thrown.
chroot_namespace | the chroot namespace. |
References NAMESPACE_NOTFOUND, and namespaces.
Referenced by add(), find_chroot_in_namespace(), get_alias_list(), get_chroot_list(), get_chroots(), and print_chroot_list_simple().
|
protected |
Find a chroot namespace.
If the namespace is not found, and exception will be thrown.
chroot_namespace | the chroot namespace. |
References NAMESPACE_NOTFOUND, and namespaces.
string_list chroot_config::get_alias_list | ( | std::string const & | chroot_namespace | ) | const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order.
chroot_namespace | the namespace to use. |
References aliases, find_namespace(), and namespace_separator.
string_list chroot_config::get_chroot_list | ( | std::string const & | chroot_namespace | ) | const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order.
chroot_namespace | the namespace to use. |
References find_namespace(), and namespace_separator.
chroot_config::chroot_list chroot_config::get_chroots | ( | std::string const & | chroot_namespace | ) | const |
Get a list of available chroots.
chroot_namespace | the chroot namespace to use. |
References find_namespace().
|
static |
Split a chroot name into a namespace and name.
name | the name to split |
chroot_namespace | the namespace (cleared if no namespace) |
chroot_name | the name without any namespace |
References namespace_separator.
Referenced by find_alias(), find_chroot(), lookup_alias(), and sbuild::chroot_facet_session::set_selected_name().
|
private |
Load a configuration file.
If there are problems with the configuration file, an error will be thrown. The file must be owned by root, not writable by other, and be a regular file.
chroot_namespace | the namespace to use for the configuration. |
file | the file to load. |
References sbuild::stat::check_mode(), sbuild::DEBUG_NOTICE, FILE_NOTREG, FILE_OPEN, FILE_OWNER, FILE_PERMS, sbuild::stat::is_regular(), sbuild::lock::LOCK_SHARED, sbuild::log_debug(), parse_data(), sbuild::stat::PERM_OTHER_WRITE, sbuild::file_lock::set_lock(), sbuild::stat::uid(), and sbuild::file_lock::unset_lock().
Referenced by add_config_directory(), and add_config_file().
|
protectedvirtual |
Load a keyfile.
If there are problems with the configuration file, an error will be thrown.
chroot_namespace | the namespace to use for the configuration. |
kconfig | the chroot configuration. |
References add(), sbuild::chroot::create(), sbuild::DEBUG_INFO, sbuild::basic_keyfile< K, P >::get_groups(), sbuild::basic_keyfile< K, P >::get_value(), and sbuild::log_debug().
Referenced by parse_data().
std::string chroot_config::lookup_alias | ( | std::string const & | namespace_hint, |
std::string const & | name | ||
) | const |
Find the chroot name referred to by an alias.
namespace_hint | the namespace to use if non was explicitly specified. |
name | the chroot name or alias. |
References aliases, sbuild::DEBUG_NOTICE, get_namespace(), sbuild::log_debug(), and namespace_separator.
|
protectedvirtual |
Parse a loaded configuration file.
If there are problems with the configuration file, an error will be thrown.
chroot_namespace | the namespace to use for the configuration. |
stream | the data stream to parse. |
References load_keyfile().
Referenced by load_data().
void chroot_config::print_chroot_list_simple | ( | std::ostream & | stream | ) | const |
Print a single line of all the available chroots to the specified stream.
stream | the stream to output to. |
References sbuild::_(), aliases, and find_namespace().
chroot_config::chroot_map chroot_config::validate_chroots | ( | std::string const & | namespace_hint, |
string_list const & | chroots | ||
) | const |
Check that all the chroots specified exist.
The specified chroot names will also be canonicalised so that they are all referenced absolutely by namespace, using chroot_namespace as a namespace hint for chroots without a namespace. If validation fails, and exception will be thrown.
namespace_hint | the namespace to use if non was explicitly specified. |
chroots | a list of chroots to validate. |
References CHROOT_NOTFOUND, CHROOTS_NOTFOUND, find_alias(), and sbuild::string_list_to_string().