sbuild
1.7.1
|
Chroot configuration. More...
#include <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::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::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< config > | ptr |
A shared_ptr to a config object. | |
Public Member Functions | |
config () | |
The constructor. | |
config (const std::string &chroot_namespace, const std::string &file) | |
The constructor. More... | |
virtual | ~config () |
The destructor. | |
void | add (const std::string &chroot_namespace, const std::string &location) |
Add a configuration file or directory. More... | |
chroot_list | get_chroots (const std::string &chroot_namespace) const |
Get a list of available chroots. More... | |
const chroot::chroot::ptr | find_chroot (const std::string &name) const |
Find a chroot by its name. More... | |
const chroot::chroot::ptr | find_chroot (const std::string &namespace_hint, const std::string &name) const |
Find a chroot by its name. More... | |
const chroot::chroot::ptr | find_chroot_in_namespace (const std::string &chroot_namespace, const std::string &name) const |
Find a chroot by its name in a specific namespace. More... | |
const chroot::chroot::ptr | find_alias (const std::string &namespace_hint, const std::string &name) const |
Find a chroot by its name or an alias. More... | |
std::string | lookup_alias (const std::string &namespace_hint, const std::string &name) const |
Find the chroot name referred to by an alias. More... | |
string_list | get_chroot_list (const std::string &chroot_namespace) const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order. More... | |
string_list | get_alias_list (const std::string &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 (const std::string &namespace_hint, const string_list &chroots) const |
Check that all the chroots specified exist. More... | |
Static Public Member Functions | |
static void | get_namespace (const std::string &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 (const std::string &chroot_namespace, chroot::chroot::ptr &chroot, const keyfile &kconfig) |
Add a chroot. More... | |
chroot_map & | find_namespace (const std::string &chroot_namespace) |
Find a chroot namespace. More... | |
chroot_map const & | find_namespace (const std::string &chroot_namespace) const |
Find a chroot namespace. More... | |
virtual void | parse_data (const std::string &chroot_namespace, std::istream &stream) |
Parse a loaded configuration file. More... | |
virtual void | load_keyfile (const std::string &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 (const std::string &chroot_namespace, const std::string &file) |
Add a configuration file. More... | |
void | add_config_directory (const std::string &chroot_namespace, const std::string &dir) |
Add a configuration directory. More... | |
void | load_data (const std::string &chroot_namespace, const std::string &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.
sbuild::chroot::config::config | ( | const std::string & | chroot_namespace, |
const std::string & | 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 sbuild::chroot::config::add | ( | const std::string & | chroot_namespace, |
const std::string & | 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 config().
|
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::keyfile::get_line(), sbuild::log_exception_warning(), namespace_separator, sbuild::keyfile::PASSTHROUGH_G, sbuild::keyfile::PASSTHROUGH_GK, sbuild::keyfile::PASSTHROUGH_LG, sbuild::keyfile::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 chroot::ptr sbuild::chroot::config::find_alias | ( | const std::string & | namespace_hint, |
const std::string & | 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 sbuild::DEBUG_NOTICE, and sbuild::log_debug().
const chroot::ptr sbuild::chroot::config::find_chroot | ( | const std::string & | 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().
const chroot::ptr sbuild::chroot::config::find_chroot | ( | const std::string & | namespace_hint, |
const std::string & | 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 chroot::ptr sbuild::chroot::config::find_chroot_in_namespace | ( | const std::string & | chroot_namespace, |
const std::string & | 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(), and get_chroots().
|
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 sbuild::chroot::config::get_alias_list | ( | const std::string & | chroot_namespace) | const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order.
chroot_namespace | the namespace to use. |
string_list sbuild::chroot::config::get_chroot_list | ( | const std::string & | chroot_namespace) | const |
Get the names (including aliases) of all the available chroots, sorted in alphabetical order.
chroot_namespace | the namespace to use. |
config::chroot_list sbuild::chroot::config::get_chroots | ( | const std::string & | 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 |
Referenced by find_chroot(), 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, sbuild::stat::is_regular(), sbuild::lock::LOCK_SHARED, sbuild::log_debug(), 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 sbuild::DEBUG_INFO, sbuild::keyfile::get_groups(), sbuild::keyfile::get_value(), and sbuild::log_debug().
std::string sbuild::chroot::config::lookup_alias | ( | const std::string & | namespace_hint, |
const std::string & | 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 sbuild::DEBUG_NOTICE, and sbuild::log_debug().
|
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. |
void sbuild::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::_().
config::chroot_map sbuild::chroot::config::validate_chroots | ( | const std::string & | namespace_hint, |
const string_list & | 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 sbuild::string_list_to_string().