summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog19
-rw-r--r--TODO6
-rw-r--r--sbuild/sbuild-chroot-block-device.cc47
-rw-r--r--sbuild/sbuild-chroot-config.cc11
-rw-r--r--sbuild/sbuild-chroot-file.cc43
-rw-r--r--sbuild/sbuild-chroot-file.h19
-rw-r--r--sbuild/sbuild-chroot-lvm-snapshot.cc34
-rw-r--r--sbuild/sbuild-chroot-plain.cc18
-rw-r--r--sbuild/sbuild-chroot-source.cc58
-rw-r--r--sbuild/sbuild-chroot.cc224
-rw-r--r--sbuild/sbuild-keyfile.h285
11 files changed, 518 insertions, 246 deletions
diff --git a/ChangeLog b/ChangeLog
index 198adc2a..0c4f270d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
2006-06-29 Roger Leigh <rleigh@debian.org>
+ * TODO: Remove completed item.
+
+ * sbuild/sbuild-chroot-config.cc
+ (parse_data): Remove exception wrapper, now that sbuild::keyfile
+ throws exceptions containing more detailed information.
+
+ * sbuild/sbuild-chroot-file.cc
+ (get_file_repack, set_file_repack): New methods to get and set
+ file repack status.
+
+ * All chroot get_keyfile and set_keyfile methods are implemented
+ in terms of the new keyfile::[gs]et_object_(list_)value methods.
+
+ * sbuild/sbuild-keyfile.h: Add templated static methods for
+ getting and setting key values and list values using pointers to
+ methods of other objects.
+
+2006-06-29 Roger Leigh <rleigh@debian.org>
+
* test/sbuild-keyfile.cc: Add test for getting line numbers.
* sbuild/sbuild-keyfile.h:
diff --git a/TODO b/TODO
index 229da789..81c3d96b 100644
--- a/TODO
+++ b/TODO
@@ -44,12 +44,6 @@ PLANNED
like namespace bugs in doxygen. It would be great if we could fix
the code by fully qualifying the namespace where appropriate.
-* Chroot config errors should report the keyfile line number.
-
- This is difficult, because the keyfile parsing is completed, and the
- line numbers are lost. Perhaps the keyfile should cache the line
- numbers during read and recompute on write?
-
* Add API to run multiple commands to replace auth::run().
diff --git a/sbuild/sbuild-chroot-block-device.cc b/sbuild/sbuild-chroot-block-device.cc
index c07499a0..5e82af9b 100644
--- a/sbuild/sbuild-chroot-block-device.cc
+++ b/sbuild/sbuild-chroot-block-device.cc
@@ -62,6 +62,9 @@ chroot_block_device::get_device () const
void
chroot_block_device::set_device (std::string const& device)
{
+ if (!is_absname(device))
+ throw error(device, DEVICE_ABS);
+
this->device = device;
}
@@ -92,6 +95,9 @@ chroot_block_device::get_location () const
void
chroot_block_device::set_location (std::string const& location)
{
+ if (!location.empty() && !is_absname(location))
+ throw error(location, LOCATION_ABS);
+
chroot::set_location(location);
}
@@ -186,14 +192,14 @@ chroot_block_device::get_keyfile (keyfile& keyfile) const
{
chroot::get_keyfile(keyfile);
- keyfile.set_value(get_name(), "device",
- get_device());
+ keyfile::set_object_value(*this, &chroot_block_device::get_device,
+ keyfile, get_name(), "device");
- keyfile.set_value(get_name(), "mount-options",
- get_mount_options());
+ keyfile::set_object_value(*this, &chroot_block_device::get_mount_options,
+ keyfile, get_name(), "mount-options");
- keyfile.set_value(get_name(), "location",
- get_location());
+ keyfile::set_object_value(*this, &chroot_block_device::get_location,
+ keyfile, get_name(), "location");
}
void
@@ -201,28 +207,17 @@ chroot_block_device::set_keyfile (keyfile const& keyfile)
{
chroot::set_keyfile(keyfile);
- std::string device;
- if (keyfile.get_value(get_name(), "device",
- keyfile::PRIORITY_REQUIRED, device))
- {
- if (!is_absname(device))
- throw error(device, DEVICE_ABS);
- set_device(device);
- }
+ keyfile::get_object_value(*this, &chroot_block_device::set_device,
+ keyfile, get_name(), "device",
+ keyfile::PRIORITY_REQUIRED);
- std::string mount_options;
- if (keyfile.get_value(get_name(), "mount-options",
- keyfile::PRIORITY_OPTIONAL, mount_options))
- set_mount_options(mount_options);
+ keyfile::get_object_value(*this, &chroot_block_device::set_mount_options,
+ keyfile, get_name(), "mount-options",
+ keyfile::PRIORITY_OPTIONAL);
- std::string location;
- if (keyfile.get_value(get_name(), "location",
- keyfile::PRIORITY_OPTIONAL, location))
- {
- if (!location.empty() && !is_absname(location))
- throw error(location, LOCATION_ABS);
- set_location(location);
- }
+ keyfile::get_object_value(*this, &chroot_block_device::set_location,
+ keyfile, get_name(), "location",
+ keyfile::PRIORITY_OPTIONAL);
}
/*
diff --git a/sbuild/sbuild-chroot-config.cc b/sbuild/sbuild-chroot-config.cc
index 97bf01e7..661dd2c4 100644
--- a/sbuild/sbuild-chroot-config.cc
+++ b/sbuild/sbuild-chroot-config.cc
@@ -478,16 +478,7 @@ chroot_config::parse_data (std::istream& stream,
chroot::ptr chroot = chroot::create(type);
chroot->set_name(*group);
- try
- {
- kconfig >> chroot;
- }
- catch (const runtime_error& e)
- {
- format fmt(_("%1% chroot"));
- fmt % *group;
- throw error(fmt.str(), e.what());
- }
+ kconfig >> chroot;
add(chroot);
diff --git a/sbuild/sbuild-chroot-file.cc b/sbuild/sbuild-chroot-file.cc
index c1c06d8e..73919c96 100644
--- a/sbuild/sbuild-chroot-file.cc
+++ b/sbuild/sbuild-chroot-file.cc
@@ -77,9 +77,24 @@ chroot_file::get_file () const
void
chroot_file::set_file (std::string const& file)
{
+ if (!is_absname(file))
+ throw error(file, FILE_ABS);
+
this->file = file;
}
+bool
+chroot_file::get_file_repack () const
+{
+ return this->repack;
+}
+
+void
+chroot_file::set_file_repack (bool repack)
+{
+ this->repack = repack;
+}
+
std::string const&
chroot_file::get_chroot_type () const
{
@@ -154,12 +169,12 @@ chroot_file::get_keyfile (keyfile& keyfile) const
chroot::get_keyfile(keyfile);
chroot_source::get_keyfile(keyfile);
- keyfile.set_value(get_name(), "file",
- get_file());
+ keyfile::set_object_value(*this, &chroot_file::get_file,
+ keyfile, get_name(), "file");
if (get_active())
- keyfile.set_value(get_name(), "file-repack",
- this->repack);
+ keyfile::set_object_value(*this, &chroot_file::get_file_repack,
+ keyfile, get_name(), "file-repack");
}
void
@@ -168,19 +183,15 @@ chroot_file::set_keyfile (keyfile const& keyfile)
chroot::set_keyfile(keyfile);
chroot_source::set_keyfile(keyfile);
- std::string file;
- if (keyfile.get_value(get_name(), "file",
- keyfile::PRIORITY_REQUIRED, file))
- {
- if (!is_absname(file))
- throw error(file, FILE_ABS);
- set_file(file);
- }
+ keyfile::get_object_value(*this, &chroot_file::set_file,
+ keyfile, get_name(), "file",
+ keyfile::PRIORITY_REQUIRED);
- keyfile.get_value(get_name(), "file-repack",
- get_active() ?
- keyfile::PRIORITY_REQUIRED : keyfile::PRIORITY_DISALLOWED,
- this->repack);
+ keyfile::get_object_value(*this, &chroot_file::set_file_repack,
+ keyfile, get_name(), "file-repack",
+ get_active() ?
+ keyfile::PRIORITY_REQUIRED :
+ keyfile::PRIORITY_DISALLOWED);
}
/*
diff --git a/sbuild/sbuild-chroot-file.h b/sbuild/sbuild-chroot-file.h
index d16ad969..1127fe38 100644
--- a/sbuild/sbuild-chroot-file.h
+++ b/sbuild/sbuild-chroot-file.h
@@ -65,6 +65,25 @@ namespace sbuild
void
set_file (std::string const& file);
+ /**
+ * Get the repack status. This is true if the unpacked archive
+ * file will be repacked.
+ *
+ * @returns the repack status.
+ */
+ bool
+ get_file_repack () const;
+
+ /**
+ * Set the file repack status. Set to true if the unpacked
+ * archive file will be repacked on session cleanup, or false to
+ * discard.
+ *
+ * @param repack the repack status.
+ */
+ void
+ set_file_repack (bool repack);
+
virtual std::string const&
get_chroot_type () const;
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.cc b/sbuild/sbuild-chroot-lvm-snapshot.cc
index 29e8b87e..2ab983af 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.cc
+++ b/sbuild/sbuild-chroot-lvm-snapshot.cc
@@ -76,6 +76,9 @@ chroot_lvm_snapshot::get_snapshot_device () const
void
chroot_lvm_snapshot::set_snapshot_device (std::string const& snapshot_device)
{
+ if (!is_absname(snapshot_device))
+ throw error(snapshot_device, DEVICE_ABS);
+
this->snapshot_device = snapshot_device;
}
@@ -212,11 +215,11 @@ chroot_lvm_snapshot::get_keyfile (keyfile& keyfile) const
chroot_source::get_keyfile(keyfile);
if (get_active())
- keyfile.set_value(get_name(), "lvm-snapshot-device",
- get_snapshot_device());
+ keyfile::set_object_value(*this, &chroot_lvm_snapshot::get_snapshot_device,
+ keyfile, get_name(), "lvm-snapshot-device");
- keyfile.set_value(get_name(), "lvm-snapshot-options",
- get_snapshot_options());
+ keyfile::set_object_value(*this, &chroot_lvm_snapshot::get_snapshot_options,
+ keyfile, get_name(), "lvm-snapshot-options");
}
void
@@ -225,22 +228,15 @@ chroot_lvm_snapshot::set_keyfile (keyfile const& keyfile)
chroot_block_device::set_keyfile(keyfile);
chroot_source::set_keyfile(keyfile);
- std::string snapshot_device;
- if (keyfile.get_value(get_name(), "lvm-snapshot-device",
- get_active() ?
- keyfile::PRIORITY_REQUIRED :
- keyfile::PRIORITY_DISALLOWED,
- snapshot_device))
- {
- if (!is_absname(snapshot_device))
- throw error(snapshot_device, DEVICE_ABS);
- set_snapshot_device(snapshot_device);
- }
+ keyfile::get_object_value(*this, &chroot_lvm_snapshot::set_snapshot_device,
+ keyfile, get_name(), "lvm-snapshot-device",
+ get_active() ?
+ keyfile::PRIORITY_REQUIRED :
+ keyfile::PRIORITY_DISALLOWED);
- std::string snapshot_options;
- if (keyfile.get_value(get_name(), "lvm-snapshot-options",
- keyfile::PRIORITY_REQUIRED, snapshot_options))
- set_snapshot_options(snapshot_options);
+ keyfile::get_object_value(*this, &chroot_lvm_snapshot::set_snapshot_options,
+ keyfile, get_name(), "lvm-snapshot-options",
+ keyfile::PRIORITY_REQUIRED);
}
/*
diff --git a/sbuild/sbuild-chroot-plain.cc b/sbuild/sbuild-chroot-plain.cc
index 70bc07fa..af1588e7 100644
--- a/sbuild/sbuild-chroot-plain.cc
+++ b/sbuild/sbuild-chroot-plain.cc
@@ -56,6 +56,9 @@ chroot_plain::get_location () const
void
chroot_plain::set_location (std::string const& location)
{
+ if (!is_absname(location))
+ throw error(location, LOCATION_ABS);
+
chroot::set_location(location);
}
@@ -124,8 +127,8 @@ chroot_plain::get_keyfile (keyfile& keyfile) const
{
chroot::get_keyfile(keyfile);
- keyfile.set_value(get_name(), "location",
- get_location());
+ keyfile::set_object_value(*this, &chroot_plain::get_location,
+ keyfile, get_name(), "location");
}
void
@@ -133,14 +136,9 @@ chroot_plain::set_keyfile (keyfile const& keyfile)
{
chroot::set_keyfile(keyfile);
- std::string location;
- if (keyfile.get_value(get_name(), "location",
- keyfile::PRIORITY_REQUIRED, location))
- {
- if (!is_absname(location))
- throw error(location, LOCATION_ABS);
- set_location(location);
- }
+ keyfile::get_object_value(*this, &chroot_plain::set_location,
+ keyfile, get_name(), "location",
+ keyfile::PRIORITY_REQUIRED);
}
/*
diff --git a/sbuild/sbuild-chroot-source.cc b/sbuild/sbuild-chroot-source.cc
index 4e9112ce..eeccd6e9 100644
--- a/sbuild/sbuild-chroot-source.cc
+++ b/sbuild/sbuild-chroot-source.cc
@@ -125,49 +125,37 @@ chroot_source::get_details (format_detail& detail) const
void
chroot_source::get_keyfile (keyfile& keyfile) const
{
- string_list const& source_users = get_source_users();
- keyfile.set_list_value(get_name(), "source-users",
- source_users.begin(), source_users.end());
+ keyfile::set_object_list_value(*this, &chroot_source::get_source_users,
+ keyfile, get_name(), "source-users");
- string_list const& source_groups = get_source_groups();
- keyfile.set_list_value(get_name(), "source-groups",
- source_groups.begin(), source_groups.end());
+ keyfile::set_object_list_value(*this, &chroot_source::get_source_groups,
+ keyfile, get_name(), "source-groups");
- string_list const& source_root_groups = get_source_root_groups();
- keyfile.set_list_value(get_name(), "source-root-groups",
- source_root_groups.begin(), source_root_groups.end());
+ keyfile::set_object_list_value(*this, &chroot_source::get_source_root_users,
+ keyfile, get_name(), "source-root-users");
- string_list const& source_root_users = get_source_root_users();
- keyfile.set_list_value(get_name(), "source-root-users",
- source_root_users.begin(), source_root_users.end());
+ keyfile::set_object_list_value(*this, &chroot_source::get_source_root_groups,
+ keyfile, get_name(), "source-root-groups");
}
void
chroot_source::set_keyfile (keyfile const& keyfile)
{
- string_list source_users;
- if (keyfile.get_list_value(get_name(), "source-users",
- keyfile::PRIORITY_OPTIONAL,
- source_users))
- set_source_users(source_users);
-
- string_list source_groups;
- if (keyfile.get_list_value(get_name(), "source-groups",
- keyfile::PRIORITY_OPTIONAL,
- source_groups))
- set_source_groups(source_groups);
-
- string_list source_root_users;
- if (keyfile.get_list_value(get_name(), "source-root-users",
- keyfile::PRIORITY_OPTIONAL,
- source_root_users))
- set_source_root_users(source_root_users);
-
- string_list source_root_groups;
- if (keyfile.get_list_value(get_name(), "source-root-groups",
- keyfile::PRIORITY_OPTIONAL,
- source_root_groups))
- set_source_root_groups(source_root_groups);
+ keyfile::get_object_list_value(*this, &chroot_source::set_source_users,
+ keyfile, get_name(), "source-users",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot_source::set_source_groups,
+ keyfile, get_name(), "source-groups",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot_source::set_source_root_users,
+ keyfile, get_name(), "source-root-users",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot_source::set_source_root_groups,
+ keyfile, get_name(), "source-root-groups",
+ keyfile::PRIORITY_OPTIONAL);
}
/*
diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc
index 9f6f919a..4932a229 100644
--- a/sbuild/sbuild-chroot.cc
+++ b/sbuild/sbuild-chroot.cc
@@ -168,6 +168,8 @@ sbuild::chroot::get_mount_location () const
void
sbuild::chroot::set_mount_location (std::string const& location)
{
+ if (!location.empty() && !is_absname(location))
+ throw error(location, LOCATION_ABS);
this->mount_location = location;
}
@@ -180,6 +182,9 @@ sbuild::chroot::get_location () const
void
sbuild::chroot::set_location (std::string const& location)
{
+ if (!is_absname(location))
+ throw error(location, LOCATION_ABS);
+
this->location = location;
}
@@ -198,6 +203,8 @@ sbuild::chroot::get_mount_device () const
void
sbuild::chroot::set_mount_device (std::string const& device)
{
+ if (!device.empty() && !is_absname(device))
+ throw error(device, DEVICE_ABS);
this->mount_device = device;
}
@@ -472,59 +479,54 @@ sbuild::chroot::print_details (std::ostream& stream) const
void
sbuild::chroot::get_keyfile (keyfile& keyfile) const
{
- keyfile.remove_group(this->name);
+ keyfile.remove_group(get_name());
- keyfile.set_value(this->name, "type",
- get_chroot_type());
+ keyfile::set_object_value(*this, &chroot::get_chroot_type,
+ keyfile, get_name(), "type");
- keyfile.set_value(this->name, "active",
- get_active());
+ keyfile::set_object_value(*this, &chroot::get_active,
+ keyfile, get_name(), "active");
- keyfile.set_value(this->name, "run-setup-scripts",
- get_run_setup_scripts());
+ keyfile::set_object_value(*this, &chroot::get_run_setup_scripts,
+ keyfile, get_name(), "run-setup-scripts");
- keyfile.set_value(this->name, "run-exec-scripts",
- get_run_exec_scripts());
+ keyfile::set_object_value(*this, &chroot::get_run_exec_scripts,
+ keyfile, get_name(), "run-exec-scripts");
- keyfile.set_value(this->name, "priority",
- get_priority());
+ keyfile::set_object_value(*this, &chroot::get_priority,
+ keyfile, get_name(), "priority");
- string_list const& aliases = get_aliases();
- keyfile.set_list_value(this->name, "aliases",
- aliases.begin(), aliases.end());
+ keyfile::set_object_list_value(*this, &chroot::get_aliases,
+ keyfile, get_name(), "aliases");
- keyfile.set_value(this->name, "description",
- get_description());
+ keyfile::set_object_value(*this, &chroot::get_description,
+ keyfile, get_name(), "description");
- string_list const& groups = get_groups();
- keyfile.set_list_value(this->name, "groups",
- groups.begin(), groups.end());
+ keyfile::set_object_list_value(*this, &chroot::get_users,
+ keyfile, get_name(), "users");
- string_list const& users = get_users();
- keyfile.set_list_value(this->name, "users",
- users.begin(), users.end());
+ keyfile::set_object_list_value(*this, &chroot::get_groups,
+ keyfile, get_name(), "groups");
- string_list const& root_users = get_root_users();
- keyfile.set_list_value(this->name, "root-users",
- root_users.begin(), root_users.end());
+ keyfile::set_object_list_value(*this, &chroot::get_root_users,
+ keyfile, get_name(), "root-users");
- string_list const& root_groups = get_root_groups();
- keyfile.set_list_value(this->name, "root-groups",
- root_groups.begin(), root_groups.end());
+ keyfile::set_object_list_value(*this, &chroot::get_root_groups,
+ keyfile, get_name(), "root-groups");
if (get_active())
- keyfile.set_value(this->name, "mount-location",
- get_mount_location());
+ keyfile::set_object_value(*this, &chroot::get_mount_location,
+ keyfile, get_name(), "mount-location");
if (get_active())
- keyfile.set_value(this->name, "mount-device",
- get_mount_device());
+ keyfile::set_object_value(*this, &chroot::get_mount_device,
+ keyfile, get_name(), "mount-device");
- string_list const& command_prefix = get_command_prefix();
- keyfile.set_list_value(this->name, "command-prefix",
- command_prefix.begin(), command_prefix.end());
+ keyfile::set_object_list_value(*this, &chroot::get_command_prefix,
+ keyfile, get_name(), "command-prefix");
- keyfile.set_value(this->name, "personality",
+ // TODO: Add stream operators to persona.
+ keyfile.set_value(get_name(), "personality",
get_persona().get_name());
}
@@ -533,94 +535,68 @@ sbuild::chroot::set_keyfile (keyfile const& keyfile)
{
// This is set not in the configuration file, but set in the keyfile
// manually. The user must not have the ability to set this option.
- bool active(false);
- if (keyfile.get_value(this->name, "active",
- keyfile::PRIORITY_REQUIRED, active))
- set_active(active);
-
- bool run_setup_scripts(false);
- if (keyfile.get_value(this->name, "run-setup-scripts",
- keyfile::PRIORITY_OPTIONAL, run_setup_scripts))
- set_run_setup_scripts(run_setup_scripts);
-
- bool run_exec_scripts(false);
- if (keyfile.get_value(this->name, "run-session-scripts",
- keyfile::PRIORITY_DEPRECATED, run_exec_scripts))
- set_run_exec_scripts(run_exec_scripts);
- if (keyfile.get_value(this->name, "run-exec-scripts",
- keyfile::PRIORITY_OPTIONAL, run_exec_scripts))
- set_run_exec_scripts(run_exec_scripts);
-
- int priority(0);
- if (keyfile.get_value(this->name, "priority",
- keyfile::PRIORITY_OPTIONAL, priority))
- set_priority(priority);
-
- string_list aliases;
- if (keyfile.get_list_value(this->name, "aliases",
- keyfile::PRIORITY_OPTIONAL,
- aliases))
- set_aliases(aliases);
-
- std::string description;
- if (keyfile.get_locale_string(this->name, "description",
- keyfile::PRIORITY_OPTIONAL, description))
- set_description(description);
-
- string_list users;
- if (keyfile.get_list_value(this->name, "users",
- keyfile::PRIORITY_OPTIONAL,
- users))
- set_users(users);
-
- string_list groups;
- if (keyfile.get_list_value(this->name, "groups",
- keyfile::PRIORITY_OPTIONAL,
- groups))
- set_groups(groups);
-
- string_list root_users;
- if (keyfile.get_list_value(this->name, "root-users",
- keyfile::PRIORITY_OPTIONAL,
- root_users))
- set_root_users(root_users);
-
- string_list root_groups;
- if (keyfile.get_list_value(this->name, "root-groups",
- keyfile::PRIORITY_OPTIONAL,
- root_groups))
- set_root_groups(root_groups);
-
- std::string mount_location;
- if (keyfile.get_value(this->name, "mount-location",
- get_active() ?
- keyfile::PRIORITY_REQUIRED : keyfile::PRIORITY_DISALLOWED,
- mount_location))
- {
- if (!is_absname(mount_location))
- throw error(mount_location, LOCATION_ABS);
- set_mount_location(mount_location);
- }
-
- std::string mount_device;
- if (keyfile.get_value(this->name, "mount-device",
- get_active() ?
- keyfile::PRIORITY_OPTIONAL : keyfile::PRIORITY_DISALLOWED,
- mount_device))
- {
- if (!mount_device.empty() && !is_absname(mount_device))
- throw error(mount_device, DEVICE_ABS);
- set_mount_device(mount_device);
- }
-
- string_list command_prefix;
- if (keyfile.get_list_value(this->name, "command-prefix",
- keyfile::PRIORITY_OPTIONAL,
- command_prefix))
- set_command_prefix(command_prefix);
-
+ keyfile::get_object_value(*this, &chroot::set_active,
+ keyfile, get_name(), "active",
+ keyfile::PRIORITY_REQUIRED);
+
+ keyfile::get_object_value(*this, &chroot::set_run_setup_scripts,
+ keyfile, get_name(), "run-setup-scripts",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_value(*this, &chroot::set_run_exec_scripts,
+ keyfile, get_name(), "run-session-scripts",
+ keyfile::PRIORITY_DEPRECATED);
+ keyfile::get_object_value(*this, &chroot::set_run_exec_scripts,
+ keyfile, get_name(), "run-exec-scripts",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_value(*this, &chroot::set_priority,
+ keyfile, get_name(), "priority",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot::set_aliases,
+ keyfile, get_name(), "aliases",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_value(*this, &chroot::set_description,
+ keyfile, get_name(), "description",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot::set_users,
+ keyfile, get_name(), "users",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot::set_groups,
+ keyfile, get_name(), "groups",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot::set_root_users,
+ keyfile, get_name(), "root-users",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_list_value(*this, &chroot::set_root_groups,
+ keyfile, get_name(), "root-groups",
+ keyfile::PRIORITY_OPTIONAL);
+
+ keyfile::get_object_value(*this, &chroot::set_mount_location,
+ keyfile, get_name(), "mount-location",
+ get_active() ?
+ keyfile::PRIORITY_REQUIRED :
+ keyfile::PRIORITY_DISALLOWED);
+
+ keyfile::get_object_value(*this, &chroot::set_mount_device,
+ keyfile, get_name(), "mount-device",
+ get_active() ?
+ keyfile::PRIORITY_OPTIONAL :
+ keyfile::PRIORITY_DISALLOWED);
+
+ keyfile::get_object_list_value(*this, &chroot::set_command_prefix,
+ keyfile, get_name(), "command-prefix",
+ keyfile::PRIORITY_OPTIONAL);
+
+ // TODO: Add stream operators to persona.
std::string persona_name;
- if (keyfile.get_value(this->name, "personality",
+ if (keyfile.get_value(get_name(), "personality",
keyfile::PRIORITY_OPTIONAL,
persona_name))
{
@@ -634,7 +610,7 @@ sbuild::chroot::set_keyfile (keyfile const& keyfile)
log_warning()
<< format(_("%1% chroot: personality \"%2%\" is unknown.\n"))
- % this->name % persona_name;
+ % get_name() % persona_name;
log_info()
<< format(_("Valid personalities: %1%\n")) % plist.str();
}
diff --git a/sbuild/sbuild-keyfile.h b/sbuild/sbuild-keyfile.h
index 906b924f..eb189d0b 100644
--- a/sbuild/sbuild-keyfile.h
+++ b/sbuild/sbuild-keyfile.h
@@ -782,6 +782,291 @@ namespace sbuild
group_map_type groups;
/// The separator used as a list item delimiter.
char separator;
+
+ public:
+ /**
+ * Set a key value from an object method return value. This is
+ * the same as calling set_value directly, but handles exceptions
+ * being thrown by the object method, which are turned into
+ * parse_error exceptions.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ */
+ template<class C, typename T>
+ static void
+ set_object_value (C const& object,
+ T (C::* method)() const,
+ keyfile& keyfile,
+ std::string const& group,
+ std::string const& key)
+ {
+ try
+ {
+ keyfile.set_value(group, key, (object.*method)());
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(group, key, parse_error::NONE, e.what());
+ }
+ }
+
+ /**
+ * Set a key value from an object method return value reference.
+ * This is the same as calling set_value directly, but handles
+ * exceptions being thrown by the object method, which are turned
+ * into parse_error exceptions.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ */
+ template<class C, typename T>
+ static void
+ set_object_value (C const& object,
+ T const& (C::* method)() const,
+ keyfile& keyfile,
+ std::string const& group,
+ std::string const& key)
+ {
+ try
+ {
+ keyfile.set_value(group, key, (object.*method)());
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(group, key, parse_error::NONE, e.what());
+ }
+ }
+
+ /**
+ * Set a key list value from an object method return value. The
+ * method must return a container with begin() and end() methods
+ * which return forward iterators. This is the same as calling
+ * set_list_value directly, but handles exceptions being thrown by
+ * the object method, which are turned into parse_error
+ * exceptions.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ */
+ template<class C, typename T>
+ static void
+ set_object_list_value (C const& object,
+ T (C::* method)() const,
+ keyfile& keyfile,
+ std::string const& group,
+ std::string const& key)
+ {
+ try
+ {
+ keyfile.set_list_value(group, key,
+ (object.*method)().begin(),
+ (object.*method)().end());
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(group, key, parse_error::NONE, e.what());
+ }
+ }
+
+ /**
+ * Set a key list value from an object method return value. The
+ * method must return a container reference with begin() and end()
+ * methods which return forward iterators. This is the same as
+ * calling set_list_value directly, but handles exceptions being
+ * thrown by the object method, which are turned into parse_error
+ * exceptions.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ */
+ template<class C, typename T>
+ static void
+ set_object_list_value (C const& object,
+ T const& (C::* method)() const,
+ keyfile& keyfile,
+ std::string const& group,
+ std::string const& key)
+ {
+ try
+ {
+ keyfile.set_list_value(group, key,
+ (object.*method)().begin(),
+ (object.*method)().end());
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(group, key, parse_error::NONE, e.what());
+ }
+ }
+
+ /**
+ * Get a key value and set it in an object using an object method.
+ * This is the same as calling get_value directly, but handles
+ * exceptions being thrown by the object method, and
+ * deserialisation errors, which are turned into parse_error
+ * exceptions pointing to the group, key and line number in the
+ * input file.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ * @param priority the key priority.
+ */
+ template<class C, typename T>
+ static void
+ get_object_value (C& object,
+ void (C::* method)(T param),
+ keyfile const& keyfile,
+ std::string const& group,
+ std::string const& key,
+ keyfile::priority priority)
+ {
+ T value;
+ if (keyfile.get_value(group, key, priority, value))
+ {
+ try
+ {
+ (object.*method)(value);
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(keyfile.get_line(group, key),
+ group, key, parse_error::NONE, e.what());
+ }
+ }
+ }
+
+ /**
+ * Get a key value and set it by reference in an object using an
+ * object method. This is the same as calling get_value directly,
+ * but handles exceptions being thrown by the object method, and
+ * deserialisation errors, which are turned into parse_error
+ * exceptions pointing to the group, key and line number in the
+ * input file.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ * @param priority the key priority.
+ */
+ template<class C, typename T>
+ static void
+ get_object_value (C& object,
+ void (C::* method)(T const& param),
+ keyfile const& keyfile,
+ std::string const& group,
+ std::string const& key,
+ keyfile::priority priority)
+ {
+ T value;
+ if (keyfile.get_value(group, key, priority, value))
+ {
+ try
+ {
+ (object.*method)(value);
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(keyfile.get_line(group, key),
+ group, key, parse_error::NONE, e.what());
+ }
+ }
+ }
+
+ /**
+ * Get a key list value and set it in an object using an object
+ * method. This is the same as calling get_list_value directly,
+ * but handles exceptions being thrown by the object method, and
+ * deserialisation errors, which are turned into parse_error
+ * exceptions pointing to the group, key and line number in the
+ * input file.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ * @param priority the key priority.
+ */
+ template<class C, typename T>
+ static void
+ get_object_list_value (C& object,
+ void (C::* method)(T param),
+ keyfile const& keyfile,
+ std::string const& group,
+ std::string const& key,
+ keyfile::priority priority)
+ {
+ T value;
+ if (keyfile.get_list_value(group, key, priority, value))
+ {
+ try
+ {
+ (object.*method)(value);
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(keyfile.get_line(group, key),
+ group, key, parse_error::NONE, e.what());
+ }
+ }
+ }
+
+ /**
+ * Get a key list value and set it by reference in an object using
+ * an object method. This is the same as calling get_list_value
+ * directly, but handles exceptions being thrown by the object
+ * method, and deserialisation errors, which are turned into
+ * parse_error exceptions pointing to the group, key and line
+ * number in the input file.
+ *
+ * @param object the object to use.
+ * @param method the object method to call.
+ * @param keyfile the keyfile to use.
+ * @param group the group the key is in.
+ * @param key the key to set.
+ * @param priority the key priority.
+ */
+ template<class C, typename T>
+ static void
+ get_object_list_value (C& object,
+ void (C::* method)(T const& param),
+ keyfile const& keyfile,
+ std::string const& group,
+ std::string const& key,
+ keyfile::priority priority)
+ {
+ T value;
+ if (keyfile.get_list_value(group, key, priority, value))
+ {
+ try
+ {
+ (object.*method)(value);
+ }
+ catch (runtime_error const& e)
+ {
+ throw parse_error(keyfile.get_line(group, key),
+ group, key, parse_error::NONE, e.what());
+ }
+ }
+ }
};
}