[buildd-tools-devel] [PATCH 16/17] [chroot] Extract interface into own header
Jan-Marek Glogowski
glogow at fbihome.de
Tue Jun 30 18:05:54 UTC 2009
Moves the interface functions into sbuild-chroot-iface.h.
---
sbuild/Makefile.am | 1 +
sbuild/sbuild-chroot-block-device.cc | 2 +-
sbuild/sbuild-chroot-directory.cc | 2 +-
sbuild/sbuild-chroot-file.cc | 2 +-
sbuild/sbuild-chroot-iface.h | 166 ++++++++++++++++++++++++++++++++++
sbuild/sbuild-chroot-loopback.cc | 2 +-
sbuild/sbuild-chroot-lvm-snapshot.cc | 2 +-
sbuild/sbuild-chroot-mountable.cc | 4 +-
sbuild/sbuild-chroot-mountable.h | 10 ++-
sbuild/sbuild-chroot-plain.cc | 2 +-
sbuild/sbuild-chroot-plain.h | 2 +-
sbuild/sbuild-chroot-source.cc | 2 +-
sbuild/sbuild-chroot-source.h | 16 ++--
sbuild/sbuild-chroot.h | 114 ++---------------------
sbuild/sbuild-session.cc | 2 +-
15 files changed, 203 insertions(+), 126 deletions(-)
create mode 100644 sbuild/sbuild-chroot-iface.h
diff --git a/sbuild/Makefile.am b/sbuild/Makefile.am
index 5c29893..1a12bb1 100644
--- a/sbuild/Makefile.am
+++ b/sbuild/Makefile.am
@@ -34,6 +34,7 @@ sbuild_public_h_sources = \
sbuild-chroot-block-device.h \
sbuild-chroot-directory.h \
sbuild-chroot-file.h \
+ sbuild-chroot-iface.h \
sbuild-chroot-mountable.h \
sbuild-chroot-plain.h \
sbuild-chroot-source.h \
diff --git a/sbuild/sbuild-chroot-block-device.cc b/sbuild/sbuild-chroot-block-device.cc
index f5b47fb..aee8a8e 100644
--- a/sbuild/sbuild-chroot-block-device.cc
+++ b/sbuild/sbuild-chroot-block-device.cc
@@ -178,7 +178,7 @@ chroot_block_device::setup_lock (chroot::setup_type type,
}
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_block_device::get_session_flags () const
{
return SESSION_NOFLAGS
diff --git a/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc
index 1aff50e..7789bba 100644
--- a/sbuild/sbuild-chroot-directory.cc
+++ b/sbuild/sbuild-chroot-directory.cc
@@ -104,7 +104,7 @@ chroot_directory::setup_lock (chroot::setup_type type,
}
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_directory::get_session_flags () const
{
#ifdef SBUILD_FEATURE_UNION
diff --git a/sbuild/sbuild-chroot-file.cc b/sbuild/sbuild-chroot-file.cc
index aef8664..88fdf22 100644
--- a/sbuild/sbuild-chroot-file.cc
+++ b/sbuild/sbuild-chroot-file.cc
@@ -142,7 +142,7 @@ chroot_file::setup_lock (chroot::setup_type type,
}
}
-chroot::session_flags
+chroot_iface::session_flags
chroot_file::get_session_flags () const
{
return SESSION_CREATE | chroot_source::get_session_flags();
diff --git a/sbuild/sbuild-chroot-iface.h b/sbuild/sbuild-chroot-iface.h
new file mode 100644
index 0000000..0216edb
--- /dev/null
+++ b/sbuild/sbuild-chroot-iface.h
@@ -0,0 +1,166 @@
+/* Copyright © 2005-2008 Roger Leigh <rleigh at debian.org>
+ *
+ * schroot is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * schroot is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ *********************************************************************/
+
+#ifndef SBUILD_CHROOT_IFACE_H
+#define SBUILD_CHROOT_IFACE_H
+
+#include <sbuild/sbuild-custom-error.h>
+#include <sbuild/sbuild-environment.h>
+#include <sbuild/sbuild-format-detail.h>
+#include <sbuild/sbuild-keyfile.h>
+#include <sbuild/sbuild-personality.h>
+#include <sbuild/sbuild-regex.h>
+#include <sbuild/sbuild-tr1types.h>
+
+#include <ostream>
+#include <string>
+
+namespace sbuild
+{
+
+ /**
+ * Common chroot interface.
+ */
+ class chroot_iface
+ {
+ public:
+ /// Chroot session properties
+ enum session_flags
+ {
+ SESSION_NOFLAGS = 0, ///< No flags are set.
+ SESSION_CREATE = 1 << 0, ///< The chroot supports session creation.
+ SESSION_CLONE = 1 << 1, ///< The chroot supports cloning.
+ SESSION_PURGE = 1 << 2 ///< The chroot should be purged.
+ };
+
+ /// Error codes.
+ enum error_code
+ {
+ CHROOT_CREATE, ///< Chroot creation failed.
+ CHROOT_DEVICE, ///< Chroot device name not set.
+ CHROOT_TYPE, ///< Unknown chroot type.
+ DEVICE_ABS, ///< Device must have an absolute path.
+ DEVICE_LOCK, ///< Failed to lock device.
+ DEVICE_NOTBLOCK, ///< File is not a block device.
+ DEVICE_UNLOCK, ///< Failed to unlock device.
+ DIRECTORY_ABS, ///< Directory must have an absolute path.
+ FILE_ABS, ///< File must have an absolute path.
+ FILE_LOCK, ///< Failed to acquire lock.
+ FILE_NOTREG, ///< File is not a regular file.
+ FILE_OWNER, ///< File is not owned by user root.
+ FILE_PERMS, ///< File has write permissions for others.
+ FILE_UNLOCK, ///< Failed to discard lock.
+ LOCATION_ABS, ///< Location must have an absolute path.
+ SESSION_UNLINK, ///< Failed to unlink session file.
+ SESSION_WRITE ///< Failed to write session file.
+ };
+
+ /// Exception type.
+ typedef custom_error<error_code> error;
+
+ protected:
+ /// The destructor.
+ virtual ~chroot_iface () {}
+
+ public:
+ /**
+ * Get the session flags of the chroot. These determine how the
+ * Session controlling the chroot will operate.
+ *
+ * @returns the session flags.
+ */
+ virtual session_flags
+ get_session_flags () const = 0;
+
+ /**
+ * Set environment. Set the environment that the setup scripts
+ * will see during execution.
+ *
+ * @param env the environment to set.
+ */
+ virtual void
+ setup_env (environment& env) = 0;
+
+ /**
+ * Get detailed information about the chroot for output.
+ *
+ * @param detail the details to output to.
+ */
+ virtual void
+ get_details (format_detail& detail) const = 0;
+
+ /**
+ * Copy the chroot properties into a keyfile. The keyfile group
+ * with the name of the chroot will be set; if it already exists,
+ * it will be removed before setting it.
+ *
+ * @param keyfile the keyfile to use.
+ */
+ virtual void
+ get_keyfile (keyfile& keyfile) const = 0;
+
+ /**
+ * Set the chroot properties from a keyfile. The chroot name must
+ * have previously been set, so that the correct keyfile group may
+ * be determined.
+ *
+ * @param keyfile the keyfile to get the properties from.
+ * @param used_keys a list of the keys used will be set.
+ */
+ virtual void
+ set_keyfile (keyfile const& keyfile,
+ string_list& used_keys) = 0;
+
+ };
+
+ /**
+ * Bitwise-OR of specifed session properties
+ * @param lhs session properties
+ * @param rhs session properties
+ * @returns result of OR.
+ */
+ chroot_iface::session_flags
+ inline operator | (chroot_iface::session_flags const& lhs,
+ chroot_iface::session_flags const& rhs)
+ {
+ return static_cast<chroot_iface::session_flags>
+ (static_cast<int>(lhs) | static_cast<int>(rhs));
+ }
+
+ /**
+ * Bitwise-AND of specifed session properties
+ * @param lhs session properties
+ * @param rhs session properties
+ * @returns result of AND.
+ */
+ chroot_iface::session_flags
+ inline operator & (chroot_iface::session_flags const& lhs,
+ chroot_iface::session_flags const& rhs)
+ {
+ return static_cast<chroot_iface::session_flags>
+ (static_cast<int>(lhs) & static_cast<int>(rhs));
+ }
+}
+
+#endif /* SBUILD_CHROOT_IFACE_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */
diff --git a/sbuild/sbuild-chroot-loopback.cc b/sbuild/sbuild-chroot-loopback.cc
index 607f194..52a0b3e 100644
--- a/sbuild/sbuild-chroot-loopback.cc
+++ b/sbuild/sbuild-chroot-loopback.cc
@@ -153,7 +153,7 @@ chroot_loopback::setup_lock (chroot::setup_type type,
#endif
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_loopback::get_session_flags () const
{
return SESSION_NOFLAGS
diff --git a/sbuild/sbuild-chroot-lvm-snapshot.cc b/sbuild/sbuild-chroot-lvm-snapshot.cc
index 8670add..b8925de 100644
--- a/sbuild/sbuild-chroot-lvm-snapshot.cc
+++ b/sbuild/sbuild-chroot-lvm-snapshot.cc
@@ -194,7 +194,7 @@ chroot_lvm_snapshot::setup_lock (chroot::setup_type type,
}
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_lvm_snapshot::get_session_flags () const
{
return SESSION_CREATE | chroot_source::get_session_flags();
diff --git a/sbuild/sbuild-chroot-mountable.cc b/sbuild/sbuild-chroot-mountable.cc
index 43345b8..43ef59c 100644
--- a/sbuild/sbuild-chroot-mountable.cc
+++ b/sbuild/sbuild-chroot-mountable.cc
@@ -123,10 +123,10 @@ chroot_mountable::setup_env (environment& env)
env.add("CHROOT_MOUNT_UUID", get_mount_uuid(false));
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_mountable::get_session_flags () const
{
- return chroot::SESSION_NOFLAGS;
+ return SESSION_NOFLAGS;
}
void
diff --git a/sbuild/sbuild-chroot-mountable.h b/sbuild/sbuild-chroot-mountable.h
index c19b3e4..f48ebdd 100644
--- a/sbuild/sbuild-chroot-mountable.h
+++ b/sbuild/sbuild-chroot-mountable.h
@@ -29,7 +29,7 @@ namespace sbuild
*
* The device will be mounted on demand.
*/
- class chroot_mountable
+ class chroot_mountable : virtual public chroot_iface
{
protected:
/// The constructor.
@@ -120,12 +120,13 @@ namespace sbuild
virtual std::string const&
get_mount_uuid (bool abort_on_error = false);
+ public:
+ virtual session_flags
+ get_session_flags () const;
+
virtual void
setup_env (environment& env);
- virtual chroot::session_flags
- get_session_flags () const;
-
protected:
virtual void
get_details (format_detail& detail) const;
@@ -137,6 +138,7 @@ namespace sbuild
set_keyfile (keyfile const& keyfile,
string_list& used_keys);
+ protected:
/**
* Returns the status of the UUID detection.
*
diff --git a/sbuild/sbuild-chroot-plain.cc b/sbuild/sbuild-chroot-plain.cc
index 808fcb9..23dacb8 100644
--- a/sbuild/sbuild-chroot-plain.cc
+++ b/sbuild/sbuild-chroot-plain.cc
@@ -92,7 +92,7 @@ chroot_plain::setup_lock (chroot::setup_type type,
/* By default, plain chroots do no locking. */
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_plain::get_session_flags () const
{
return SESSION_NOFLAGS;
diff --git a/sbuild/sbuild-chroot-plain.h b/sbuild/sbuild-chroot-plain.h
index 3d245cb..4844d57 100644
--- a/sbuild/sbuild-chroot-plain.h
+++ b/sbuild/sbuild-chroot-plain.h
@@ -27,7 +27,7 @@ namespace sbuild
/**
* A chroot located in the filesystem (mounts disabled).
*/
- class chroot_plain : virtual public chroot
+ class chroot_plain : public chroot
{
protected:
/// The constructor.
diff --git a/sbuild/sbuild-chroot-source.cc b/sbuild/sbuild-chroot-source.cc
index bdd4bec..88bd53a 100644
--- a/sbuild/sbuild-chroot-source.cc
+++ b/sbuild/sbuild-chroot-source.cc
@@ -118,7 +118,7 @@ chroot_source::setup_env (environment& env)
{
}
-sbuild::chroot::session_flags
+chroot_iface::session_flags
chroot_source::get_session_flags () const
{
const chroot *base = dynamic_cast<const chroot *>(this);
diff --git a/sbuild/sbuild-chroot-source.h b/sbuild/sbuild-chroot-source.h
index a597dac..382e4ff 100644
--- a/sbuild/sbuild-chroot-source.h
+++ b/sbuild/sbuild-chroot-source.h
@@ -20,6 +20,7 @@
#define SBUILD_CHROOT_SOURCE_H
#include <sbuild/sbuild-chroot.h>
+#include <sbuild/sbuild-chroot-iface.h>
namespace sbuild
{
@@ -35,7 +36,7 @@ namespace sbuild
* chroot, and must call clone_source_setup() to set up the source
* chroot.
*/
- class chroot_source
+ class chroot_source : virtual public chroot_iface
{
protected:
/// The constructor.
@@ -135,20 +136,21 @@ namespace sbuild
virtual void
set_source_root_groups (string_list const& groups);
- void
+ public:
+ virtual session_flags
+ get_session_flags () const;
+
+ virtual void
setup_env (environment& env);
protected:
- virtual chroot::session_flags
- get_session_flags () const;
-
virtual void
get_details (format_detail& detail) const;
- void
+ virtual void
get_keyfile (keyfile& keyfile) const;
- void
+ virtual void
set_keyfile (keyfile const& keyfile,
string_list& used_keys);
diff --git a/sbuild/sbuild-chroot.h b/sbuild/sbuild-chroot.h
index e0a2431..5790ffc 100644
--- a/sbuild/sbuild-chroot.h
+++ b/sbuild/sbuild-chroot.h
@@ -26,6 +26,7 @@
#include <sbuild/sbuild-personality.h>
#include <sbuild/sbuild-regex.h>
#include <sbuild/sbuild-tr1types.h>
+#include <sbuild/sbuild-chroot-iface.h>
#include <ostream>
#include <string>
@@ -40,7 +41,7 @@ namespace sbuild
* configuration file, and may be initialised directly from an open
* keyfile.
*/
- class chroot
+ class chroot : virtual public chroot_iface
{
public:
/// Type of setup to perform.
@@ -53,40 +54,6 @@ namespace sbuild
EXEC_STOP ///< End executing a command in an active chroot.
};
- /// Chroot session properties
- enum session_flags
- {
- SESSION_NOFLAGS = 0, ///< No flags are set.
- SESSION_CREATE = 1 << 0, ///< The chroot supports session creation.
- SESSION_CLONE = 1 << 1, ///< The chroot supports cloning.
- SESSION_PURGE = 1 << 2 ///< The chroot should be purged.
- };
-
- /// Error codes.
- enum error_code
- {
- CHROOT_CREATE, ///< Chroot creation failed.
- CHROOT_DEVICE, ///< Chroot device name not set.
- CHROOT_TYPE, ///< Unknown chroot type.
- DEVICE_ABS, ///< Device must have an absolute path.
- DEVICE_LOCK, ///< Failed to lock device.
- DEVICE_NOTBLOCK, ///< File is not a block device.
- DEVICE_UNLOCK, ///< Failed to unlock device.
- DIRECTORY_ABS, ///< Directory must have an absolute path.
- FILE_ABS, ///< File must have an absolute path.
- FILE_LOCK, ///< Failed to acquire lock.
- FILE_NOTREG, ///< File is not a regular file.
- FILE_OWNER, ///< File is not owned by user root.
- FILE_PERMS, ///< File has write permissions for others.
- FILE_UNLOCK, ///< Failed to discard lock.
- LOCATION_ABS, ///< Location must have an absolute path.
- SESSION_UNLINK, ///< Failed to unlink session file.
- SESSION_WRITE ///< Failed to write session file.
- };
-
- /// Exception type.
- typedef custom_error<error_code> error;
-
/// A shared_ptr to a chroot object.
typedef std::tr1::shared_ptr<chroot> ptr;
@@ -447,15 +414,6 @@ public:
get_chroot_type () const = 0;
/**
- * Set environment. Set the environment that the setup scripts
- * will see during execution.
- *
- * @param env the environment to set.
- */
- virtual void
- setup_env (environment& env);
-
- /**
* Lock a chroot during setup. The locking technique (if any) may
* vary depending upon the chroot type and setup stage. For
* example, during creation of an LVM snapshot a block device
@@ -516,15 +474,6 @@ public:
public:
/**
- * Get the session flags of the chroot. These determine how the
- * Session controlling the chroot will operate.
- *
- * @returns the session flags.
- */
- virtual session_flags
- get_session_flags () const = 0;
-
- /**
* Print detailed information about the chroot to a stream. The
* information is printed in plain text with one line per
* property.
@@ -569,14 +518,6 @@ public:
protected:
/**
- * Get detailed information about the chroot for output.
- *
- * @param detail the details to output to.
- */
- virtual void
- get_details (format_detail& detail) const;
-
- /**
* Print detailed information about the chroot to a stream. The
* information is printed in plain text with one line per
* property.
@@ -586,24 +527,17 @@ public:
void
print_details (std::ostream& stream) const;
- /**
- * Copy the chroot properties into a keyfile. The keyfile group
- * with the name of the chroot will be set; if it already exists,
- * it will be removed before setting it.
- *
- * @param keyfile the keyfile to use.
- */
+ public:
+ virtual void
+ setup_env (environment& env);
+
+ protected:
+ virtual void
+ get_details (format_detail& detail) const;
+
virtual void
get_keyfile (keyfile& keyfile) const;
- /**
- * Set the chroot properties from a keyfile. The chroot name must
- * have previously been set, so that the correct keyfile group may
- * be determined.
- *
- * @param keyfile the keyfile to get the properties from.
- * @param used_keys a list of the keys used will be set.
- */
virtual void
set_keyfile (keyfile const& keyfile,
string_list& used_keys);
@@ -645,34 +579,6 @@ public:
personality persona;
};
- /**
- * Bitwise-OR of specifed session properties
- * @param lhs session properties
- * @param rhs session properties
- * @returns result of OR.
- */
- chroot::session_flags
- inline operator | (chroot::session_flags const& lhs,
- chroot::session_flags const& rhs)
- {
- return static_cast<chroot::session_flags>
- (static_cast<int>(lhs) | static_cast<int>(rhs));
- }
-
- /**
- * Bitwise-AND of specifed session properties
- * @param lhs session properties
- * @param rhs session properties
- * @returns result of AND.
- */
- chroot::session_flags
- inline operator & (chroot::session_flags const& lhs,
- chroot::session_flags const& rhs)
- {
- return static_cast<chroot::session_flags>
- (static_cast<int>(lhs) & static_cast<int>(rhs));
- }
-
}
#endif /* SBUILD_CHROOT_H */
diff --git a/sbuild/sbuild-session.cc b/sbuild/sbuild-session.cc
index 0dea8bc..cba6671 100644
--- a/sbuild/sbuild-session.cc
+++ b/sbuild/sbuild-session.cc
@@ -574,7 +574,7 @@ session::run_impl ()
support session creation append a UUID to the session
ID. */
if (chroot->get_active() ||
- !(chroot->get_session_flags() & chroot::SESSION_CREATE))
+ !(chroot->get_session_flags() & chroot_iface::SESSION_CREATE))
{
if (!get_session_id().empty())
{
--
1.6.3.2
More information about the Buildd-tools-devel
mailing list