sbuild  1.7.1
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
sbuild::chroot::config Class Reference

Chroot configuration. More...

#include <config.h>

+ Collaboration diagram for sbuild::chroot::config:

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_codeerror
 Exception type.
 
typedef std::shared_ptr< configptr
 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_mapfind_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...
 

Detailed Description

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.

Member Enumeration Documentation

Error codes.

Enumerator
ALIAS_EXIST 

Alias already associated with chroot.

CHROOT_NOTFOUND 

Chroot not found.

CHROOTS_NOTFOUND 

Chroots not found.

CHROOT_EXIST 

A chroot or alias already exists with this name.

FILE_NOTREG 

File is not a regular file.

FILE_OPEN 

Failed to open file.

FILE_OWNER 

File is not owned by user root.

FILE_PERMS 

File has write permissions for others.

NAME_INVALID 

Invalid name.

NAMESPACE_NOTFOUND 

No such namespace.

Constructor & Destructor Documentation

sbuild::chroot::config::config ( const std::string &  chroot_namespace,
const std::string &  file 
)

The constructor.

Parameters
chroot_namespacethe namespace to use for initialised configuration.
fileinitialise using a configuration file or a whole directory containing configuration files.

References add(), and namespaces.

Member Function Documentation

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.

Parameters
chroot_namespacethe namespace to use for initialised configuration.
locationinitialise using a configuration file or a whole directory containing configuration files.
Todo:
Remove and require explicit use of add_config_file or add_config_directory; the caller should be aware which is required.

References add_config_directory(), and add_config_file().

Referenced by config().

+ Here is the caller graph for this function:

void sbuild::chroot::config::add ( const std::string &  chroot_namespace,
chroot::chroot::ptr chroot,
const keyfile kconfig 
)
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.

Parameters
chroot_namespacethe namespace to use for the chroot.
chrootthe chroot to add.
kconfigthe 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().

void sbuild::chroot::config::add_config_directory ( const std::string &  chroot_namespace,
const std::string &  dir 
)
private

Add a configuration directory.

The configuration files in the directory specified will all be loaded.

Parameters
chroot_namespacethe namespace to use for initialised configuration.
dirthe 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().

+ Here is the caller graph for this function:

void sbuild::chroot::config::add_config_file ( const std::string &  chroot_namespace,
const std::string &  file 
)
private

Add a configuration file.

The configuration file specified will be loaded.

Parameters
chroot_namespacethe namespace to use for initialised configuration.
filethe file to load.

References sbuild::DEBUG_NOTICE, load_data(), and sbuild::log_debug().

Referenced by add().

+ Here is the caller graph for this function:

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.

Parameters
namespace_hintthe namespace to use if non was explicitly specified.
namethe chroot name or alias.
Returns
the chroot if found, otherwise 0.

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.

Parameters
namethe chroot name
Returns
the chroot if found, otherwise 0.

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.

Parameters
namespace_hintthe namespace to use if non was explicitly specified.
namethe chroot name
Returns
the chroot if found, otherwise 0.

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.

Parameters
chroot_namespacethe namespace to search.
namethe chroot name
Returns
the chroot if found, otherwise 0.

References sbuild::DEBUG_NOTICE, find_namespace(), and sbuild::log_debug().

Referenced by find_chroot().

+ Here is the caller graph for this function:

config::chroot_map & sbuild::chroot::config::find_namespace ( const std::string &  chroot_namespace)
protected

Find a chroot namespace.

If the namespace is not found, and exception will be thrown.

Parameters
chroot_namespacethe chroot namespace.
Returns
the namespace.

References NAMESPACE_NOTFOUND, and namespaces.

Referenced by add(), find_chroot_in_namespace(), and get_chroots().

+ Here is the caller graph for this function:

config::chroot_map const & sbuild::chroot::config::find_namespace ( const std::string &  chroot_namespace) const
protected

Find a chroot namespace.

If the namespace is not found, and exception will be thrown.

Parameters
chroot_namespacethe chroot namespace.
Returns
the 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.

Parameters
chroot_namespacethe namespace to use.
Returns
the list. The list will be empty if no chroots are available.
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.

Parameters
chroot_namespacethe namespace to use.
Returns
the list. The list will be empty if no chroots are available.
config::chroot_list sbuild::chroot::config::get_chroots ( const std::string &  chroot_namespace) const

Get a list of available chroots.

Parameters
chroot_namespacethe chroot namespace to use.
Returns
a list of available chroots. The list will be empty if no chroots are available.

References find_namespace().

void sbuild::chroot::config::get_namespace ( const std::string &  name,
std::string &  chroot_namespace,
std::string &  chroot_name 
)
static

Split a chroot name into a namespace and name.

Parameters
namethe name to split
chroot_namespacethe namespace (cleared if no namespace)
chroot_namethe name without any namespace

Referenced by find_chroot(), and sbuild::chroot::facet::session::set_selected_name().

+ Here is the caller graph for this function:

void sbuild::chroot::config::load_data ( const std::string &  chroot_namespace,
const std::string &  file 
)
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.

Parameters
chroot_namespacethe namespace to use for the configuration.
filethe 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().

+ Here is the caller graph for this function:

void sbuild::chroot::config::load_keyfile ( const std::string &  chroot_namespace,
keyfile kconfig 
)
protectedvirtual

Load a keyfile.

If there are problems with the configuration file, an error will be thrown.

Parameters
chroot_namespacethe namespace to use for the configuration.
kconfigthe 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.

Parameters
namespace_hintthe namespace to use if non was explicitly specified.
namethe chroot name or alias.
Returns
the chroot name if found, otherwise an empty string.

References sbuild::DEBUG_NOTICE, and sbuild::log_debug().

void sbuild::chroot::config::parse_data ( const std::string &  chroot_namespace,
std::istream &  stream 
)
protectedvirtual

Parse a loaded configuration file.

If there are problems with the configuration file, an error will be thrown.

Parameters
chroot_namespacethe namespace to use for the configuration.
streamthe 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.

Parameters
streamthe 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.

Parameters
namespace_hintthe namespace to use if non was explicitly specified.
chrootsa list of chroots to validate.
Returns
an alias-chroot mapping.

References sbuild::string_list_to_string().


The documentation for this class was generated from the following files: