summaryrefslogtreecommitdiff
path: root/sbuild
diff options
context:
space:
mode:
Diffstat (limited to 'sbuild')
-rw-r--r--sbuild/Makefile.am2
-rw-r--r--sbuild/sbuild-chroot-directory.cc17
-rw-r--r--sbuild/sbuild-chroot-directory.h7
-rw-r--r--sbuild/sbuild-chroot-session.cc117
-rw-r--r--sbuild/sbuild-chroot-session.h140
5 files changed, 280 insertions, 3 deletions
diff --git a/sbuild/Makefile.am b/sbuild/Makefile.am
index 3235efe7..1a74feb1 100644
--- a/sbuild/Makefile.am
+++ b/sbuild/Makefile.am
@@ -36,6 +36,7 @@ sbuild_public_h_sources = \
sbuild-chroot-file.h \
sbuild-chroot-mountable.h \
sbuild-chroot-plain.h \
+ sbuild-chroot-session.h \
sbuild-chroot-source.h \
sbuild-chroot-config.h \
sbuild-chroot-union.h \
@@ -107,6 +108,7 @@ sbuild_public_cc_sources = \
sbuild-chroot-file.cc \
sbuild-chroot-mountable.cc \
sbuild-chroot-plain.cc \
+ sbuild-chroot-session.cc \
sbuild-chroot-source.cc \
sbuild-chroot-config.cc \
sbuild-ctty.cc \
diff --git a/sbuild/sbuild-chroot-directory.cc b/sbuild/sbuild-chroot-directory.cc
index 7dd63280..fe4541f7 100644
--- a/sbuild/sbuild-chroot-directory.cc
+++ b/sbuild/sbuild-chroot-directory.cc
@@ -49,6 +49,15 @@ chroot_directory::clone () const
return ptr(new chroot_directory(*this));
}
+sbuild::chroot::ptr
+chroot_directory::clone_session (std::string const& session_id) const
+{
+ ptr session(new chroot_directory(*this));
+ clone_session_setup(session, session_id);
+
+ return ptr(session);
+}
+
#ifdef SBUILD_FEATURE_UNION
sbuild::chroot::ptr
chroot_directory::clone_source () const
@@ -75,6 +84,7 @@ void
chroot_directory::setup_env (environment& env)
{
chroot_directory_base::setup_env(env);
+ chroot_session::setup_env(env);
#ifdef SBUILD_FEATURE_UNION
chroot_union::setup_env(env);
#endif // SBUILD_FEATURE_UNION
@@ -106,9 +116,9 @@ sbuild::chroot::session_flags
chroot_directory::get_session_flags () const
{
#ifdef SBUILD_FEATURE_UNION
- return SESSION_CREATE | chroot_union::get_session_flags();
+ return chroot_session::get_session_flags() | chroot_union::get_session_flags();
#else
- return SESSION_CREATE;
+ return chroot_session::get_session_flags();
#endif // SBUILD_FEATURE_UNION
}
@@ -116,6 +126,7 @@ void
chroot_directory::get_details (format_detail& detail) const
{
chroot_directory_base::get_details(detail);
+ chroot_session::get_details(detail);
#ifdef SBUILD_FEATURE_UNION
chroot_union::get_details(detail);
#endif // SBUILD_FEATURE_UNION
@@ -125,6 +136,7 @@ void
chroot_directory::get_keyfile (keyfile& keyfile) const
{
chroot_directory_base::get_keyfile(keyfile);
+ chroot_session::get_keyfile(keyfile);
#ifdef SBUILD_FEATURE_UNION
chroot_union::get_keyfile(keyfile);
#endif // SBUILD_FEATURE_UNION
@@ -135,6 +147,7 @@ chroot_directory::set_keyfile (keyfile const& keyfile,
string_list& used_keys)
{
chroot_directory_base::set_keyfile(keyfile, used_keys);
+ chroot_session::set_keyfile(keyfile, used_keys);
#ifdef SBUILD_FEATURE_UNION
chroot_union::set_keyfile(keyfile, used_keys);
#endif // SBUILD_FEATURE_UNION
diff --git a/sbuild/sbuild-chroot-directory.h b/sbuild/sbuild-chroot-directory.h
index e223e626..993d816b 100644
--- a/sbuild/sbuild-chroot-directory.h
+++ b/sbuild/sbuild-chroot-directory.h
@@ -21,6 +21,7 @@
#include <sbuild/sbuild-config.h>
#include <sbuild/sbuild-chroot-directory-base.h>
+#include <sbuild/sbuild-chroot-session.h>
#ifdef SBUILD_FEATURE_UNION
#include <sbuild/sbuild-chroot-union.h>
#endif // SBUILD_FEATURE_UNION
@@ -31,7 +32,8 @@ namespace sbuild
/**
* A chroot located in the filesystem.
*/
- class chroot_directory : public chroot_directory_base
+ class chroot_directory : public chroot_directory_base,
+ public chroot_session
#ifdef SBUILD_FEATURE_UNION
, public chroot_union
#endif // SBUILD_FEATURE_UNION
@@ -49,6 +51,9 @@ namespace sbuild
virtual chroot::ptr
clone () const;
+ virtual chroot::ptr
+ clone_session (std::string const& session_id) const;
+
#ifdef SBUILD_FEATURE_UNION
virtual chroot::ptr
clone_source () const;
diff --git a/sbuild/sbuild-chroot-session.cc b/sbuild/sbuild-chroot-session.cc
new file mode 100644
index 00000000..85baef36
--- /dev/null
+++ b/sbuild/sbuild-chroot-session.cc
@@ -0,0 +1,117 @@
+/* Copyright © 2005-2009 Roger Leigh <rleigh@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/>.
+ *
+ *********************************************************************/
+
+#include <config.h>
+
+#include "sbuild-chroot-session.h"
+#include "sbuild-format-detail.h"
+
+#include <algorithm>
+
+#include <boost/format.hpp>
+
+using boost::format;
+using namespace sbuild;
+
+chroot_session::chroot_session ():
+ session_manageable(true),
+ session_active(false)
+{
+}
+
+chroot_session::~chroot_session ()
+{
+}
+
+void
+chroot_session::clone_session_setup (chroot::ptr& clone,
+ std::string const& session_id) const
+{
+ // Disable session, delete aliases.
+ std::tr1::shared_ptr<chroot_session> session(std::tr1::dynamic_pointer_cast<chroot_session>(clone));
+ if (session)
+ {
+ session->set_session_manageable(false);
+ session->set_session_active(true);
+ }
+}
+
+bool
+chroot_session::get_session_manageable () const
+{
+ return this->session_manageable;
+}
+
+void
+chroot_session::set_session_manageable (bool manageable)
+{
+ this->session_manageable = manageable;
+}
+
+bool
+chroot_session::get_session_active () const
+{
+ return this->session_active;
+}
+
+void
+chroot_session::set_session_active (bool active)
+{
+ this->session_active = active;
+}
+
+void
+chroot_session::setup_env (environment& env)
+{
+}
+
+sbuild::chroot::session_flags
+chroot_session::get_session_flags () const
+{
+ /// @todo: Remove need for this.
+ const chroot *base = dynamic_cast<const chroot *>(this);
+ assert(base != 0);
+
+ /// If active, support session.
+ if (get_session_manageable() && !get_session_active())
+ return chroot::SESSION_CREATE;
+ else
+ return chroot::SESSION_NOFLAGS;
+}
+
+void
+chroot_session::get_details (format_detail& detail) const
+{
+}
+
+void
+chroot_session::get_keyfile (keyfile& keyfile) const
+{
+ /// @todo: Remove need for this by passing in group name
+ const chroot *base = dynamic_cast<const chroot *>(this);
+ assert(base != 0);
+}
+
+void
+chroot_session::set_keyfile (keyfile const& keyfile,
+ string_list& used_keys)
+{
+ /// @todo: Remove need for this by passing in group name
+ const chroot *base = dynamic_cast<const chroot *>(this);
+ assert(base != 0);
+}
diff --git a/sbuild/sbuild-chroot-session.h b/sbuild/sbuild-chroot-session.h
new file mode 100644
index 00000000..8a66b637
--- /dev/null
+++ b/sbuild/sbuild-chroot-session.h
@@ -0,0 +1,140 @@
+/* Copyright © 2005-2009 Roger Leigh <rleigh@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_SESSION_H
+#define SBUILD_CHROOT_SESSION_H
+
+#include <sbuild/sbuild-chroot.h>
+
+namespace sbuild
+{
+
+ /**
+ * A chroot may offer a "session" chroot in addition to its inactive
+ * copy. This interface may be implemented by any chroot wishing to
+ * provide such functionality.
+ *
+ * While this is effectively an interface, in practice this derives
+ * from sbuild::chroot, to allow setting and getting of data from a
+ * keyfile, including storing the keyfile options.
+ *
+ * Chroot types implementing chroot_session should, at a minimum,
+ * implement clone_session(). This should create and return a session
+ * chroot, and must call clone_session_setup() to set up the session
+ * chroot.
+ */
+ class chroot_session
+ {
+ protected:
+ /// The constructor.
+ chroot_session ();
+
+ friend class chroot;
+
+ public:
+ /// The destructor.
+ virtual ~chroot_session ();
+
+ /**
+ * Create a session chroot.
+ *
+ * @param session_id the identifier for the new session.
+ * @returns a session chroot.
+ */
+ virtual chroot::ptr
+ clone_session (std::string const& session_id) const = 0;
+
+ protected:
+ /**
+ * Set the defaults in the cloned session chroot.
+ *
+ * @param clone the chroot to set up.
+ * @param session_id the identifier for the new session.
+ */
+ virtual void
+ clone_session_setup (chroot::ptr& clone,
+ std::string const& session_id) const;
+
+ public:
+ /**
+ * Get if the chroot is a session manageable chroot or not.
+ *
+ * @returns true if the chroot is a session manageable chroot,
+ * otherwise false.
+ */
+ virtual bool
+ get_session_manageable () const;
+
+ /**
+ * Set if the chroot is a session manageable chroot or not.
+ *
+ * @param session true if a session chroot, manageable or false if
+ * not.
+ */
+ virtual void
+ set_session_manageable (bool manageable);
+
+ /**
+ * Get if the chroot is an active session or not.
+ *
+ * @returns true if the chroot is an active session, otherwise false.
+ */
+ virtual bool
+ get_session_active () const;
+
+ /**
+ * Set if the chroot is an active session or not.
+ *
+ * @param session true if an active session, or false if not.
+ */
+ virtual void
+ set_session_active (bool active);
+
+ void
+ setup_env (environment& env);
+
+ protected:
+ virtual chroot::session_flags
+ get_session_flags () const;
+
+ virtual void
+ get_details (format_detail& detail) const;
+
+ void
+ get_keyfile (keyfile& keyfile) const;
+
+ void
+ set_keyfile (keyfile const& keyfile,
+ string_list& used_keys);
+
+ private:
+ /// Is the chroot session or clone?
+ bool session_manageable;
+ /// Is the session active?
+ bool session_active;
+ };
+
+}
+
+#endif /* SBUILD_CHROOT_SESSION_H */
+
+/*
+ * Local Variables:
+ * mode:C++
+ * End:
+ */