[buildd-tools-devel] [PATCH 2/3] General chroot container member
Jan-Marek Glogowski
glogow at fbihome.de
Sun Mar 29 19:38:01 UTC 2009
This drops all chroot specific setters, getters and members
for a general chroot container member.
---
bin/schroot/exec/00check | 1 +
bin/schroot/setup/00check | 1 +
sbuild/sbuild-chroot-block-device.cc | 37 +++++++++++++----------------
sbuild/sbuild-chroot-block-device.h | 12 +---------
sbuild/sbuild-chroot-directory.cc | 32 +++++++++++--------------
sbuild/sbuild-chroot-directory.h | 10 +-------
sbuild/sbuild-chroot-file.cc | 36 ++++++++++++-----------------
sbuild/sbuild-chroot-file.h | 12 +---------
sbuild/sbuild-chroot-loopback.cc | 33 +++++++++++---------------
sbuild/sbuild-chroot-loopback.h | 16 +-----------
sbuild/sbuild-chroot-lvm-snapshot.cc | 8 +++---
sbuild/sbuild-chroot-plain.cc | 2 +-
sbuild/sbuild-chroot.cc | 19 +++++++++++++++
sbuild/sbuild-chroot.h | 42 +++++++++++++++++++++++++++++++++-
sbuild/sbuild-session.cc | 2 +-
test/sbuild-chroot-block-device.cc | 7 +++--
test/sbuild-chroot-directory.cc | 8 ++++--
test/sbuild-chroot-file.cc | 7 +++--
test/sbuild-chroot-lvm-snapshot.cc | 3 +-
test/sbuild-chroot-plain.cc | 10 ++++----
20 files changed, 153 insertions(+), 145 deletions(-)
diff --git a/bin/schroot/exec/00check b/bin/schroot/exec/00check
index 0caa1be..006fbde 100755
--- a/bin/schroot/exec/00check
+++ b/bin/schroot/exec/00check
@@ -51,6 +51,7 @@ if [ $1 = "exec-start" ]; then
echo "CHROOT_MOUNT_LOCATION=$CHROOT_MOUNT_LOCATION"
echo "CHROOT_LOCATION=$CHROOT_LOCATION"
echo "CHROOT_PATH=$CHROOT_PATH"
+ echo "CHROOT_CONTAINER=$CHROOT_CONTAINER"
if [ "$CHROOT_TYPE" = "plain" ] || [ "$CHROOT_TYPE" = "directory" ]; then
:
elif [ "$CHROOT_TYPE" = "file" ]; then
diff --git a/bin/schroot/setup/00check b/bin/schroot/setup/00check
index 4188c74..136d38a 100755
--- a/bin/schroot/setup/00check
+++ b/bin/schroot/setup/00check
@@ -51,6 +51,7 @@ if [ $1 = "setup-start" ] || [ $1 = "setup-recover" ]; then
echo "CHROOT_MOUNT_LOCATION=$CHROOT_MOUNT_LOCATION"
echo "CHROOT_LOCATION=$CHROOT_LOCATION"
echo "CHROOT_PATH=$CHROOT_PATH"
+ echo "CHROOT_CONTAINER=$CHROOT_CONTAINER"
if [ "$CHROOT_TYPE" = "plain" ] || [ "$CHROOT_TYPE" = "directory" ]; then
:
elif [ "$CHROOT_TYPE" = "file" ]; then
diff --git a/sbuild/sbuild-chroot-block-device.cc b/sbuild/sbuild-chroot-block-device.cc
index d06e170..ebc6fb4 100644
--- a/sbuild/sbuild-chroot-block-device.cc
+++ b/sbuild/sbuild-chroot-block-device.cc
@@ -33,8 +33,7 @@ using namespace sbuild;
chroot_block_device::chroot_block_device ():
chroot(),
- chroot_mountable(),
- device()
+ chroot_mountable()
{
}
@@ -48,19 +47,13 @@ chroot_block_device::clone () const
return ptr(new chroot_block_device(*this));
}
-std::string const&
-chroot_block_device::get_device () const
-{
- return this->device;
-}
-
void
-chroot_block_device::set_device (std::string const& device)
+chroot_block_device::set_container (std::string const& device)
{
if (!is_absname(device))
throw error(device, DEVICE_ABS);
- this->device = device;
+ chroot::set_container(device);
}
std::string const&
@@ -77,7 +70,7 @@ chroot_block_device::setup_env (environment& env)
chroot::setup_env(env);
chroot_mountable::setup_env(env);
- env.add("CHROOT_DEVICE", get_device());
+ env.add("CHROOT_DEVICE", get_container());
}
void
@@ -94,15 +87,17 @@ chroot_block_device::setup_lock (chroot::setup_type type,
(type == SETUP_STOP && lock == true))
return;
+ std::string device = get_container();
+
try
{
- if (!stat(this->device).is_block())
+ if (!stat(device).is_block())
{
- throw error(get_device(), DEVICE_NOTBLOCK);
+ throw error(device, DEVICE_NOTBLOCK);
}
else
{
- sbuild::device_lock dlock(this->device);
+ sbuild::device_lock dlock(device);
if (lock)
{
try
@@ -111,7 +106,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_LOCK, e);
+ throw error(device, DEVICE_LOCK, e);
}
}
else
@@ -122,7 +117,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_UNLOCK, e);
+ throw error(device, DEVICE_UNLOCK, e);
}
}
}
@@ -150,8 +145,8 @@ chroot_block_device::get_details (format_detail& detail) const
this->chroot::get_details(detail);
this->chroot_mountable::get_details(detail);
- if (!this->device.empty())
- detail.add(_("Device"), get_device());
+ if (!this->get_container().empty())
+ detail.add(_("Device"), get_container());
}
void
@@ -160,7 +155,8 @@ chroot_block_device::get_keyfile (keyfile& keyfile) const
chroot::get_keyfile(keyfile);
chroot_mountable::get_keyfile(keyfile);
- keyfile::set_object_value(*this, &chroot_block_device::get_device,
+ keyfile::set_object_value(*(static_cast<const chroot *>(this)),
+ &chroot_block_device::get_container,
keyfile, get_name(), "device");
}
@@ -171,8 +167,9 @@ chroot_block_device::set_keyfile (keyfile const& keyfile,
chroot::set_keyfile(keyfile, used_keys);
chroot_mountable::set_keyfile(keyfile, used_keys);
- keyfile::get_object_value(*this, &chroot_block_device::set_device,
+ keyfile::get_object_value(*this, &chroot_block_device::set_container,
keyfile, get_name(), "device",
keyfile::PRIORITY_REQUIRED);
used_keys.push_back("device");
}
+
diff --git a/sbuild/sbuild-chroot-block-device.h b/sbuild/sbuild-chroot-block-device.h
index 4ae8aff..2e86914 100644
--- a/sbuild/sbuild-chroot-block-device.h
+++ b/sbuild/sbuild-chroot-block-device.h
@@ -46,13 +46,6 @@ namespace sbuild
virtual chroot::ptr
clone () const;
- /**
- * Get the block device of the chroot.
- *
- * @returns the device.
- */
- std::string const&
- get_device () const;
/**
* Set the block device of the chroot. This is the "source" device.
@@ -63,7 +56,7 @@ namespace sbuild
* @param device the device.
*/
void
- set_device (std::string const& device);
+ set_container (std::string const& device);
std::string const&
get_chroot_type () const;
@@ -90,9 +83,6 @@ namespace sbuild
set_keyfile (keyfile const& keyfile,
string_list& used_keys);
- private:
- /// The block device to use.
- std::string device;
};
}
diff --git a/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc
index 978e750..e08e772 100644
--- a/sbuild/sbuild-chroot-directory.cc
+++ b/sbuild/sbuild-chroot-directory.cc
@@ -46,21 +46,6 @@ chroot_directory::clone () const
return ptr(new chroot_directory(*this));
}
-std::string const&
-chroot_directory::get_location () const
-{
- return chroot::get_location();
-}
-
-void
-chroot_directory::set_location (std::string const& location)
-{
- if (!is_absname(location))
- throw error(location, LOCATION_ABS);
-
- chroot::set_location(location);
-}
-
std::string
chroot_directory::get_path () const
{
@@ -69,7 +54,7 @@ chroot_directory::get_path () const
if (get_run_setup_scripts() == true)
return get_mount_location();
else
- return get_location();
+ return get_container();
}
std::string const&
@@ -114,11 +99,22 @@ chroot_directory::get_details (format_detail& detail) const
}
void
+chroot_directory::set_container (std::string const& directory)
+{
+ if (!directory.empty() && !is_absname(directory))
+ throw error(directory, LOCATION_ABS);
+
+ chroot::set_container(directory);
+ chroot::set_location(directory);
+}
+
+void
chroot_directory::get_keyfile (keyfile& keyfile) const
{
chroot::get_keyfile(keyfile);
- keyfile::set_object_value(*this, &chroot_directory::get_location,
+ keyfile::set_object_value(*(static_cast<const chroot *>(this)),
+ &chroot_directory::get_container,
keyfile, get_name(), "location");
}
@@ -128,7 +124,7 @@ chroot_directory::set_keyfile (keyfile const& keyfile,
{
chroot::set_keyfile(keyfile, used_keys);
- keyfile::get_object_value(*this, &chroot_directory::set_location,
+ keyfile::get_object_value(*this, &chroot_directory::set_container,
keyfile, get_name(), "location",
keyfile::PRIORITY_REQUIRED);
used_keys.push_back("location");
diff --git a/sbuild/sbuild-chroot-directory.h b/sbuild/sbuild-chroot-directory.h
index fe69e3b..69e25ec 100644
--- a/sbuild/sbuild-chroot-directory.h
+++ b/sbuild/sbuild-chroot-directory.h
@@ -43,20 +43,12 @@ namespace sbuild
clone () const;
/**
- * Get the directory location of the chroot.
- *
- * @returns the location.
- */
- virtual std::string const&
- get_location () const;
-
- /**
* Set the directory location of the chroot.
*
* @param location the location.
*/
virtual void
- set_location (std::string const& location);
+ set_container (std::string const& directory);
virtual std::string
get_path () const;
diff --git a/sbuild/sbuild-chroot-file.cc b/sbuild/sbuild-chroot-file.cc
index cc730a5..d02b59b 100644
--- a/sbuild/sbuild-chroot-file.cc
+++ b/sbuild/sbuild-chroot-file.cc
@@ -33,7 +33,6 @@ using namespace sbuild;
chroot_file::chroot_file ():
chroot(),
chroot_source(),
- file(),
repack(false)
{
set_run_setup_scripts(true);
@@ -62,19 +61,13 @@ chroot_file::clone_source () const
return clone;
}
-std::string const&
-chroot_file::get_file () const
-{
- return this->file;
-}
-
void
-chroot_file::set_file (std::string const& file)
+chroot_file::set_container (std::string const& file)
{
if (!is_absname(file))
throw error(file, FILE_ABS);
- this->file = file;
+ chroot::set_container(file);
}
bool
@@ -103,7 +96,7 @@ chroot_file::setup_env (environment& env)
chroot::setup_env(env);
chroot_source::setup_env(env);
- env.add("CHROOT_FILE", get_file());
+ env.add("CHROOT_FILE", get_container());
env.add("CHROOT_FILE_REPACK", this->repack);
}
@@ -115,15 +108,16 @@ chroot_file::setup_lock (chroot::setup_type type,
// Check ownership and permissions.
if (type == SETUP_START && lock == true)
{
- stat file_status(this->file);
+ std::string file = get_container();
+ stat file_status(file);
// NOTE: taken from chroot_config::check_security.
if (file_status.uid() != 0)
- throw error(this->file, FILE_OWNER);
+ throw error(file, FILE_OWNER);
if (file_status.check_mode(stat::PERM_OTHER_WRITE))
- throw error(this->file, FILE_PERMS);
+ throw error(file, FILE_PERMS);
if (!file_status.is_regular())
- throw error(this->file, FILE_NOTREG);
+ throw error(file, FILE_NOTREG);
}
/* By default, file chroots do no locking. */
@@ -131,7 +125,6 @@ chroot_file::setup_lock (chroot::setup_type type,
if ((type == SETUP_START && lock == true) ||
(type == SETUP_STOP && lock == false && status == 0))
{
-
bool start = (type == SETUP_START);
setup_session_info(start);
}
@@ -149,9 +142,9 @@ chroot_file::get_details (format_detail& detail) const
chroot::get_details(detail);
chroot_source::get_details(detail);
- if (!this->file.empty())
+ if (!get_container().empty())
detail
- .add(_("File"), get_file())
+ .add(_("File"), get_container())
.add(_("File Repack"), this->repack);
}
@@ -161,12 +154,13 @@ chroot_file::get_keyfile (keyfile& keyfile) const
chroot::get_keyfile(keyfile);
chroot_source::get_keyfile(keyfile);
- keyfile::set_object_value(*this, &chroot_file::get_file,
+ keyfile::set_object_value(*(static_cast<const chroot *>(this)),
+ &chroot_file::get_container,
keyfile, get_name(), "file");
if (get_active())
- keyfile::set_object_value(*this, &chroot_file::get_file_repack,
- keyfile, get_name(), "file-repack");
+ keyfile::set_object_value(*this, &chroot_file::get_file_repack,
+ keyfile, get_name(), "file-repack");
}
void
@@ -176,7 +170,7 @@ chroot_file::set_keyfile (keyfile const& keyfile,
chroot::set_keyfile(keyfile, used_keys);
chroot_source::set_keyfile(keyfile, used_keys);
- keyfile::get_object_value(*this, &chroot_file::set_file,
+ keyfile::get_object_value(*this, &chroot_file::set_container,
keyfile, get_name(), "file",
keyfile::PRIORITY_REQUIRED);
used_keys.push_back("file");
diff --git a/sbuild/sbuild-chroot-file.h b/sbuild/sbuild-chroot-file.h
index 0df1b85..fbf11f7 100644
--- a/sbuild/sbuild-chroot-file.h
+++ b/sbuild/sbuild-chroot-file.h
@@ -49,20 +49,12 @@ namespace sbuild
clone_source () const;
/**
- * Get the file used by the chroot.
- *
- * @returns the file.
- */
- std::string const&
- get_file () const;
-
- /**
* Set the file used by the chroot.
*
* @param file the file.
*/
void
- set_file (std::string const& file);
+ set_container (std::string const& file);
/**
* Get the repack status. This is true if the unpacked archive
@@ -109,8 +101,6 @@ namespace sbuild
string_list& used_keys);
private:
- /// The file to use.
- std::string file;
/// Should the chroot be repacked?
bool repack;
};
diff --git a/sbuild/sbuild-chroot-loopback.cc b/sbuild/sbuild-chroot-loopback.cc
index dc1d0df..ec1f41d 100644
--- a/sbuild/sbuild-chroot-loopback.cc
+++ b/sbuild/sbuild-chroot-loopback.cc
@@ -33,8 +33,7 @@ using namespace sbuild;
chroot_loopback::chroot_loopback ():
chroot(),
- chroot_mountable(),
- file()
+ chroot_mountable()
{
}
@@ -48,19 +47,13 @@ chroot_loopback::clone () const
return ptr(new chroot_loopback(*this));
}
-std::string const&
-chroot_loopback::get_file () const
-{
- return this->file;
-}
-
void
-chroot_loopback::set_file (std::string const& file)
+chroot_loopback::set_container (std::string const& file)
{
if (!is_absname(file))
throw error(file, FILE_ABS);
- this->file = file;
+ chroot_mountable::set_container(file);
}
std::string const&
@@ -77,7 +70,7 @@ chroot_loopback::setup_env (environment& env)
chroot::setup_env(env);
chroot_mountable::setup_env(env);
- env.add("CHROOT_FILE", get_file());
+ env.add("CHROOT_FILE", get_container());
}
void
@@ -88,15 +81,16 @@ chroot_loopback::setup_lock (chroot::setup_type type,
// Check ownership and permissions.
if (type == SETUP_START && lock == true)
{
- stat file_status(this->file);
+ std::string file = get_container();
+ stat file_status(file);
// NOTE: taken from chroot_config::check_security.
if (file_status.uid() != 0)
- throw error(this->file, FILE_OWNER);
+ throw error(file, FILE_OWNER);
if (file_status.check_mode(stat::PERM_OTHER_WRITE))
- throw error(this->file, FILE_PERMS);
+ throw error(file, FILE_PERMS);
if (!file_status.is_regular())
- throw error(this->file, FILE_NOTREG);
+ throw error(file, FILE_NOTREG);
}
/* By default, loopback chroots do no locking. */
@@ -114,8 +108,8 @@ chroot_loopback::get_details (format_detail& detail) const
this->chroot::get_details(detail);
this->chroot_mountable::get_details(detail);
- if (!this->file.empty())
- detail.add(_("File"), get_file());
+ if (!this->get_container().empty())
+ detail.add(_("File"), get_container());
}
void
@@ -124,7 +118,8 @@ chroot_loopback::get_keyfile (keyfile& keyfile) const
chroot::get_keyfile(keyfile);
chroot_mountable::get_keyfile(keyfile);
- keyfile::set_object_value(*this, &chroot_loopback::get_file,
+ keyfile::set_object_value(*(static_cast<const chroot *>(this)),
+ &chroot_loopback::get_container,
keyfile, get_name(), "file");
}
@@ -135,7 +130,7 @@ chroot_loopback::set_keyfile (keyfile const& keyfile,
chroot::set_keyfile(keyfile, used_keys);
chroot_mountable::set_keyfile(keyfile, used_keys);
- keyfile::get_object_value(*this, &chroot_loopback::set_file,
+ keyfile::get_object_value(*this, &chroot_loopback::set_container,
keyfile, get_name(), "file",
keyfile::PRIORITY_REQUIRED);
used_keys.push_back("file");
diff --git a/sbuild/sbuild-chroot-loopback.h b/sbuild/sbuild-chroot-loopback.h
index e4322db..9749fd8 100644
--- a/sbuild/sbuild-chroot-loopback.h
+++ b/sbuild/sbuild-chroot-loopback.h
@@ -47,21 +47,12 @@ namespace sbuild
clone () const;
/**
- * Get the file containing the chroot.
- *
- * @returns the file.
- */
- std::string const&
- get_file () const;
-
- /**
* Set the file containing the chroot.
*
* @param file the file.
*/
- void
- set_file (std::string const& file);
-
+ virtual void
+ set_container (std::string const& file);
std::string const&
get_chroot_type () const;
@@ -88,9 +79,6 @@ namespace sbuild
set_keyfile (keyfile const& keyfile,
string_list& used_keys);
- private:
- /// The file to use.
- std::string file;
};
}
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.cc b/sbuild/sbuild-chroot-lvm-snapshot.cc
index 552d128..1b5f2d7 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.cc
+++ b/sbuild/sbuild-chroot-lvm-snapshot.cc
@@ -119,7 +119,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
if (!(type == SETUP_STOP && lock == false))
{
if (type == SETUP_START)
- device = get_device();
+ device = get_container();
else
device = get_snapshot_device();
@@ -131,7 +131,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
stat file_status(device);
if (!file_status.is_block())
{
- throw error(get_device(), DEVICE_NOTBLOCK);
+ throw error(device, DEVICE_NOTBLOCK);
}
else
{
@@ -149,7 +149,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_LOCK, e);
+ throw error(device, DEVICE_LOCK, e);
}
}
else
@@ -160,7 +160,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
}
catch (sbuild::lock::error const& e)
{
- throw error(get_device(), DEVICE_UNLOCK, e);
+ throw error(device, DEVICE_UNLOCK, e);
}
}
}
diff --git a/sbuild/sbuild-chroot-plain.cc b/sbuild/sbuild-chroot-plain.cc
index 3598b5d..46b0157 100644
--- a/sbuild/sbuild-chroot-plain.cc
+++ b/sbuild/sbuild-chroot-plain.cc
@@ -32,7 +32,7 @@
using namespace sbuild;
chroot_plain::chroot_plain ():
- chroot()
+ chroot_directory()
{
}
diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc
index c22bfcd..aec634e 100644
--- a/sbuild/sbuild-chroot.cc
+++ b/sbuild/sbuild-chroot.cc
@@ -57,6 +57,7 @@ namespace
emap(sbuild::chroot::CHROOT_DEVICE, N_("Device name not set")),
// TRANSLATORS: %1% = chroot type name
emap(sbuild::chroot::CHROOT_TYPE, N_("Unknown chroot type '%1%'")),
+ emap(sbuild::chroot::CONTAINER_LEN, N_("Container string is empty")),
emap(sbuild::chroot::DEVICE_ABS, N_("Device must have an absolute path")),
emap(sbuild::chroot::DEVICE_LOCK, N_("Failed to lock device")),
emap(sbuild::chroot::DEVICE_NOTBLOCK, N_("File is not a block device")),
@@ -92,6 +93,7 @@ sbuild::chroot::chroot ():
aliases(),
environment_filter("^(BASH_ENV|CDPATH|ENV|HOSTALIASES|IFS|KRB5_CONFIG|KRBCONFDIR|KRBTKFILE|KRB_CONF|LD_.*|LOCALDOMAIN|NLSPATH|PATH_LOCALE|RES_OPTIONS|TERMINFO|TERMINFO_DIRS|TERMPATH)$"),
mount_location(),
+ container(),
location(),
active(false),
original(true),
@@ -178,12 +180,27 @@ sbuild::chroot::set_mount_location (std::string const& location)
}
std::string const&
+sbuild::chroot::get_container () const
+{
+ return this->container;
+}
+
+std::string const&
sbuild::chroot::get_location () const
{
return this->location;
}
void
+sbuild::chroot::set_container (std::string const& container)
+{
+ if (container.empty())
+ throw error(container, CONTAINER_LEN);
+
+ this->container = container;
+}
+
+void
sbuild::chroot::set_location (std::string const& location)
{
if (!location.empty() && !is_absname(location))
@@ -372,6 +389,7 @@ sbuild::chroot::setup_env (environment& env)
env.add("CHROOT_TYPE", get_chroot_type());
env.add("CHROOT_NAME", get_name());
env.add("CHROOT_DESCRIPTION", get_description());
+ env.add("CHROOT_CONTAINER", get_container());
env.add("CHROOT_LOCATION", get_location());
env.add("CHROOT_MOUNT_LOCATION", get_mount_location());
env.add("CHROOT_PATH", get_path());
@@ -459,6 +477,7 @@ sbuild::chroot::get_details (format_detail& detail) const
.add(_("Root Users"), get_root_users())
.add(_("Root Groups"), get_root_groups())
.add(_("Aliases"), get_aliases())
+ .add(_("Container"), get_container())
.add(_("Environment Filter"), get_environment_filter())
.add(_("Run Setup Scripts"), get_run_setup_scripts())
.add(_("Run Execution Scripts"), get_run_exec_scripts())
diff --git a/sbuild/sbuild-chroot.h b/sbuild/sbuild-chroot.h
index 73fa685..35292f2 100644
--- a/sbuild/sbuild-chroot.h
+++ b/sbuild/sbuild-chroot.h
@@ -34,11 +34,24 @@ namespace sbuild
{
/**
- * Common chroot data. This class contains all of the metadata
+ * Common chroot data.
+ *
+ * This class contains all of the metadata
* associated with a single chroot, for all chroot types. This is
* the in-core representation of a chroot definition in the
* configuration file, and may be initialised directly from an open
* keyfile.
+ *
+ * Except for the base directories the following functions and values
+ * define the mount directory:
+ * - get_path() returns the absolute path to the constructed chroot. This
+ * is most times the concat of get_mount_location() + get_location().
+ * - get_container() returns the container of the chroot. This is most
+ * times directly used as the mount device.
+ * - get_location() returns the absolute path of the chroot inside of the
+ * container. This is user configurable.
+ * - get_mount_location() returns the absolute path to the mount directory.
+ * This is most times a concat of get_mount_base_directory() + get_name().
*/
class chroot
{
@@ -68,6 +81,7 @@ namespace sbuild
CHROOT_CREATE, ///< Chroot creation failed.
CHROOT_DEVICE, ///< Chroot device name not set.
CHROOT_TYPE, ///< Unknown chroot type.
+ CONTAINER_LEN, ///< An empty string was supplied for the container.
DEVICE_ABS, ///< Device must have an absolute path.
DEVICE_LOCK, ///< Failed to lock device.
DEVICE_NOTBLOCK, ///< File is not a block device.
@@ -163,6 +177,18 @@ namespace sbuild
set_mount_location (std::string const& location);
/**
+ * Get the container of the chroot.
+ *
+ * This is a string, which describes the mount path to the container
+ * of the chroot, which may be most times the same as the device
+ * used by the mount command.
+ *
+ * @returns the path to the chroot container.
+ */
+ virtual std::string const&
+ get_container () const;
+
+ /**
* Get the location of the chroot. This is the path to the root
* of the chroot, and is typically the same as the mount location,
* but is overridden by the chroot type if required.
@@ -174,6 +200,18 @@ namespace sbuild
protected:
/**
+ * Set the container of the chroot.
+ *
+ * This is a string, which describes the mount path to the container
+ * of the chroot, which may be most times the same as the device
+ * used by the mount command.
+ *
+ * @param container the path to the chroot container.
+ */
+ virtual void
+ set_container (std::string const& container);
+
+ /**
* Set the location of the chroot. This is the path to the root
* of the chroot, and is typically the same as the mount location,
* but is overridden by the chroot type if required.
@@ -637,6 +675,8 @@ namespace sbuild
regex environment_filter;
/// Location to mount chroot in the filesystem (if any).
std::string mount_location;
+ /// Container of the chroot.
+ std::string container;
/// Location inside the mount location root.
std::string location;
/// Chroot activity status.
diff --git a/sbuild/sbuild-session.cc b/sbuild/sbuild-session.cc
index a497706..fda5507 100644
--- a/sbuild/sbuild-session.cc
+++ b/sbuild/sbuild-session.cc
@@ -658,7 +658,7 @@ session::run_impl ()
chroot_lvm_snapshot *snapshot = 0;
if ((snapshot = dynamic_cast<chroot_lvm_snapshot *>(chroot.get())) != 0)
{
- std::string dir(dirname(snapshot->get_device(), '/'));
+ std::string dir(dirname(snapshot->get_container(), '/'));
std::string device(dir + "/" + this->session_id);
snapshot->set_snapshot_device(device);
}
diff --git a/test/sbuild-chroot-block-device.cc b/test/sbuild-chroot-block-device.cc
index bb8e721..b83f8e8 100644
--- a/test/sbuild-chroot-block-device.cc
+++ b/test/sbuild-chroot-block-device.cc
@@ -62,7 +62,7 @@ public:
{
test_chroot_base<chroot_block_device>::setUp();
sbuild::chroot_block_device *c = dynamic_cast<sbuild::chroot_block_device *>(chroot.get());
- c->set_device("/dev/testdev");
+ c->set_container("/dev/testdev");
c->set_mount_options("-t jfs -o quota,rw");
}
@@ -71,8 +71,8 @@ public:
{
sbuild::chroot_block_device *c = dynamic_cast<sbuild::chroot_block_device *>(chroot.get());
CPPUNIT_ASSERT(c);
- c->set_device("/dev/some/device");
- CPPUNIT_ASSERT(c->get_device() == "/dev/some/device");
+ c->set_container("/dev/some/device");
+ CPPUNIT_ASSERT(c->get_container() == "/dev/some/device");
}
void
@@ -98,6 +98,7 @@ public:
expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
expected.add("CHROOT_PATH", "/mnt/mount-location");
expected.add("CHROOT_DEVICE", "/dev/testdev");
+ expected.add("CHROOT_CONTAINER", "/dev/testdev");
expected.add("CHROOT_MOUNT_OPTIONS", "-t jfs -o quota,rw");
expected.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
expected.add("CHROOT_SESSION_CLONE", "false");
diff --git a/test/sbuild-chroot-directory.cc b/test/sbuild-chroot-directory.cc
index 9bbc2cd..44739bf 100644
--- a/test/sbuild-chroot-directory.cc
+++ b/test/sbuild-chroot-directory.cc
@@ -62,7 +62,7 @@ public:
{
test_chroot_base<chroot_directory>::setUp();
sbuild::chroot_directory *c = dynamic_cast<sbuild::chroot_directory *>(chroot.get());
- c->set_location("/srv/chroot/example-chroot");
+ c->set_container("/srv/chroot/example-chroot");
}
void
@@ -73,10 +73,10 @@ public:
chroot->set_run_setup_scripts(true);
CPPUNIT_ASSERT(chroot->get_mount_location() == "/mnt/mount-location");
chroot->set_run_setup_scripts(false);
- c->set_location("/mnt/mount-location/example");
+ c->set_container("/mnt/mount-location/example");
chroot->set_mount_location("");
CPPUNIT_ASSERT(c->get_location() == "/mnt/mount-location/example");
- CPPUNIT_ASSERT(chroot->get_location() == "/mnt/mount-location/example");
+ CPPUNIT_ASSERT(c->get_container() == "/mnt/mount-location/example");
CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location/example");
CPPUNIT_ASSERT(chroot->get_mount_location() == "");
}
@@ -93,6 +93,7 @@ public:
expected.add("CHROOT_NAME", "test-name");
expected.add("CHROOT_DESCRIPTION", "test-description");
expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
+ expected.add("CHROOT_CONTAINER", "/srv/chroot/example-chroot");
expected.add("CHROOT_LOCATION", "/srv/chroot/example-chroot");
expected.add("CHROOT_PATH", "/srv/chroot/example-chroot");
expected.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
@@ -113,6 +114,7 @@ public:
expected.add("CHROOT_DESCRIPTION", "test-description");
expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
expected.add("CHROOT_LOCATION", "/srv/chroot/example-chroot");
+ expected.add("CHROOT_CONTAINER", "/srv/chroot/example-chroot");
expected.add("CHROOT_PATH", "/mnt/mount-location");
expected.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
expected.add("CHROOT_SESSION_CLONE", "false");
diff --git a/test/sbuild-chroot-file.cc b/test/sbuild-chroot-file.cc
index d153f92..430ce7d 100644
--- a/test/sbuild-chroot-file.cc
+++ b/test/sbuild-chroot-file.cc
@@ -61,7 +61,7 @@ public:
{
test_chroot_base<chroot_file>::setUp();
sbuild::chroot_file *c = dynamic_cast<sbuild::chroot_file *>(chroot.get());
- c->set_file("/srv/chroot/example.tar.bz2");
+ c->set_container("/srv/chroot/example.tar.bz2");
}
void
@@ -69,8 +69,8 @@ public:
{
sbuild::chroot_file *c = dynamic_cast<sbuild::chroot_file *>(chroot.get());
CPPUNIT_ASSERT(c);
- c->set_file("/srv/chroot-images/unstable.tar.gz");
- CPPUNIT_ASSERT(c->get_file() == "/srv/chroot-images/unstable.tar.gz");
+ c->set_container("/srv/chroot-images/unstable.tar.gz");
+ CPPUNIT_ASSERT(c->get_container() == "/srv/chroot-images/unstable.tar.gz");
}
void test_chroot_type()
@@ -84,6 +84,7 @@ public:
expected.add("CHROOT_TYPE", "file");
expected.add("CHROOT_NAME", "test-name");
expected.add("CHROOT_DESCRIPTION", "test-description");
+ expected.add("CHROOT_CONTAINER", "/srv/chroot/example.tar.bz2");
expected.add("CHROOT_FILE", "/srv/chroot/example.tar.bz2");
expected.add("CHROOT_FILE_REPACK", "false");
expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
diff --git a/test/sbuild-chroot-lvm-snapshot.cc b/test/sbuild-chroot-lvm-snapshot.cc
index 7da7bdb..9ae57de 100644
--- a/test/sbuild-chroot-lvm-snapshot.cc
+++ b/test/sbuild-chroot-lvm-snapshot.cc
@@ -63,7 +63,7 @@ public:
{
test_chroot_base<chroot_lvm_snapshot>::setUp();
sbuild::chroot_lvm_snapshot *c = dynamic_cast<sbuild::chroot_lvm_snapshot *>(chroot.get());
- c->set_device("/dev/testdev");
+ c->set_container("/dev/testdev");
c->set_mount_options("-t jfs -o quota,rw");
c->set_snapshot_device("/dev/snaptestdev");
c->set_snapshot_options("--size 1G");
@@ -104,6 +104,7 @@ public:
expected.add("CHROOT_MOUNT_LOCATION", "/mnt/mount-location");
expected.add("CHROOT_PATH", "/mnt/mount-location");
expected.add("CHROOT_DEVICE", "/dev/testdev");
+ expected.add("CHROOT_CONTAINER", "/dev/testdev");
expected.add("CHROOT_MOUNT_OPTIONS", "-t jfs -o quota,rw");
expected.add("CHROOT_LVM_SNAPSHOT_NAME", sbuild::basename(c->get_snapshot_device()));
expected.add("CHROOT_LVM_SNAPSHOT_DEVICE", "/dev/snaptestdev");
diff --git a/test/sbuild-chroot-plain.cc b/test/sbuild-chroot-plain.cc
index ca2a572..2bb23d9 100644
--- a/test/sbuild-chroot-plain.cc
+++ b/test/sbuild-chroot-plain.cc
@@ -61,7 +61,7 @@ public:
test_chroot_base<chroot_plain>::setUp();
sbuild::chroot_plain *c = dynamic_cast<sbuild::chroot_plain *>(chroot.get());
c->set_mount_location("");
- c->set_location("/srv/chroot/example-chroot");
+ c->set_container("/srv/chroot/example-chroot");
}
void
@@ -69,10 +69,9 @@ public:
{
sbuild::chroot_plain *c = dynamic_cast<sbuild::chroot_plain *>(chroot.get());
CPPUNIT_ASSERT(c);
- c->set_location("/mnt/mount-location/example");
- CPPUNIT_ASSERT(c->get_location() == "/mnt/mount-location/example");
- CPPUNIT_ASSERT(chroot->get_location() == "/mnt/mount-location/example");
- CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location/example");
+ c->set_container("/mnt/mount-directory/example");
+ CPPUNIT_ASSERT(c->get_container() == "/mnt/mount-directory/example");
+ CPPUNIT_ASSERT(c->get_path() == "/mnt/mount-directory/example");
CPPUNIT_ASSERT(chroot->get_mount_location() == "");
}
@@ -88,6 +87,7 @@ public:
expected.add("CHROOT_NAME", "test-name");
expected.add("CHROOT_DESCRIPTION", "test-description");
expected.add("CHROOT_LOCATION", "/srv/chroot/example-chroot");
+ expected.add("CHROOT_CONTAINER", "/srv/chroot/example-chroot");
expected.add("CHROOT_PATH", "/srv/chroot/example-chroot");
expected.add("CHROOT_SCRIPT_CONFIG", sbuild::normalname(std::string(PACKAGE_SYSCONF_DIR) + "/script-defaults"));
expected.add("CHROOT_SESSION_CLONE", "false");
--
1.6.2.1
More information about the Buildd-tools-devel
mailing list