Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions

sbuild::chroot_config Class Reference

Chroot configuration. More...

#include <sbuild-chroot-config.h>

Collaboration diagram for sbuild::chroot_config:

List of all members.

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::ptrchroot_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_codeerror
 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.
virtual ~chroot_config ()
 The destructor.
void add (std::string const &chroot_namespace, std::string const &location)
 Add a configuration file or directory.
chroot_list get_chroots (std::string const &chroot_namespace) const
 Get a list of available chroots.
const chroot::ptr find_chroot (std::string const &name) const
 Find a chroot by its name.
const chroot::ptr find_chroot (std::string const &namespace_hint, std::string const &name) const
 Find a chroot by its name.
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.
const chroot::ptr find_alias (std::string const &namespace_hint, std::string const &name) const
 Find a chroot by its name or an alias.
std::string lookup_alias (std::string const &namespace_hint, std::string const &name) const
 Find the chroot name referred to by an alias.
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.
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.
void print_chroot_list_simple (std::ostream &stream) const
 Print a single line of all the available chroots to the specified stream.
chroot_map validate_chroots (std::string const &namespace_hint, string_list const &chroots) const
 Check that all the chroots specified exist.

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.

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.
chroot_mapfind_namespace (std::string const &chroot_namespace)
 Find a chroot namespace.
chroot_map const & find_namespace (std::string const &chroot_namespace) const
 Find a chroot namespace.
virtual void parse_data (std::string const &chroot_namespace, std::istream &stream)
 Parse a loaded configuration file.
virtual void load_keyfile (std::string const &chroot_namespace, keyfile &kconfig)
 Load a keyfile.

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.
void add_config_directory (std::string const &chroot_namespace, std::string const &dir)
 Add a configuration directory.
void load_data (std::string const &chroot_namespace, std::string const &file)
 Load a configuration file.

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

chroot_config::chroot_config ( std::string const &  chroot_namespace,
std::string const &  file 
)

The constructor.

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


Member Function Documentation

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.

Parameters:
chroot_namespace the namespace to use for initialised configuration.
location initialise 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 chroot_config(), and load_keyfile().

Here is the caller graph for this function:

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

void chroot_config::add_config_directory ( std::string const &  chroot_namespace,
std::string const &  dir 
) [private]

Add a configuration directory.

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

Parameters:
chroot_namespace the namespace to use for initialised configuration.
dir the directory containing the files to load.

References sbuild::DEBUG_NOTICE, FILE_NOTREG, 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 chroot_config::add_config_file ( std::string const &  chroot_namespace,
std::string const &  file 
) [private]

Add a configuration file.

The configuration file specified will be loaded.

Parameters:
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().

Here is the caller graph for this function:

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.

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

References aliases, sbuild::DEBUG_NOTICE, find_chroot(), get_namespace(), sbuild::log_debug(), and namespace_separator.

Referenced by validate_chroots().

Here is the caller graph for this function:

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.

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

References find_chroot_in_namespace(), and get_namespace().

Referenced by find_alias().

Here is the caller graph for this function:

const sbuild::chroot::ptr chroot_config::find_chroot ( std::string const &  namespace_hint,
std::string const &  name 
) const

Find a chroot by its name.

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

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.

Parameters:
chroot_namespace the namespace to search.
name the 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:

chroot_config::chroot_map & chroot_config::find_namespace ( std::string const &  chroot_namespace  )  [protected]

Find a chroot namespace.

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

Parameters:
chroot_namespace the chroot namespace.
Returns:
the 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().

Here is the caller graph for this function:

chroot_config::chroot_map const & chroot_config::find_namespace ( std::string const &  chroot_namespace  )  const [protected]

Find a chroot namespace.

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

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

Parameters:
chroot_namespace the namespace to use.
Returns:
the list. The list will be empty if no chroots are available.

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.

Parameters:
chroot_namespace the namespace to use.
Returns:
the list. The list will be empty if no chroots are available.

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.

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

References find_namespace().

void chroot_config::get_namespace ( std::string const &  name,
std::string &  chroot_namespace,
std::string &  chroot_name 
) [static]

Split a chroot name into a namespace and name.

Parameters:
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().

Here is the caller graph for this function:

void chroot_config::load_data ( std::string const &  chroot_namespace,
std::string const &  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_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().

Here is the caller graph for this function:

void chroot_config::load_keyfile ( std::string const &  chroot_namespace,
keyfile kconfig 
) [protected, virtual]

Load a keyfile.

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

Parameters:
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().

Here is the caller graph for this function:

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.

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

References aliases, sbuild::DEBUG_NOTICE, get_namespace(), sbuild::log_debug(), and namespace_separator.

void chroot_config::parse_data ( std::string const &  chroot_namespace,
std::istream &  stream 
) [protected, virtual]

Parse a loaded configuration file.

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

Parameters:
chroot_namespace the namespace to use for the configuration.
stream the data stream to parse.

References load_keyfile().

Referenced by load_data().

Here is the caller graph for this function:

void chroot_config::print_chroot_list_simple ( std::ostream &  stream  )  const

Print a single line of all the available chroots to the specified stream.

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

Parameters:
namespace_hint the namespace to use if non was explicitly specified.
chroots a list of chroots to validate.
Returns:
an alias-chroot mapping.

References CHROOT_NOTFOUND, CHROOTS_NOTFOUND, find_alias(), and sbuild::string_list_to_string().


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