summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/sbuild/Makefile.am2
-rw-r--r--lib/sbuild/chroot/chroot.cc11
-rw-r--r--lib/sbuild/chroot/chroot.h12
-rw-r--r--lib/sbuild/chroot/facet/directory-base.h7
-rw-r--r--lib/sbuild/chroot/facet/plain.cc117
-rw-r--r--lib/sbuild/chroot/facet/plain.h87
-rw-r--r--lib/sbuild/chroot/plain.cc36
-rw-r--r--lib/sbuild/chroot/plain.h19
-rw-r--r--test/sbuild/chroot/chroot.cc11
-rw-r--r--test/sbuild/chroot/plain.cc11
10 files changed, 117 insertions, 196 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am
index 69a10b35..85a120a2 100644
--- a/lib/sbuild/Makefile.am
+++ b/lib/sbuild/Makefile.am
@@ -29,6 +29,7 @@ lib_sbuild_public_h_sources = \
lib/sbuild/chroot/facet/directory-base.h \
lib/sbuild/chroot/facet/mountable.h \
lib/sbuild/chroot/facet/personality.h \
+ lib/sbuild/chroot/facet/plain.h \
lib/sbuild/chroot/facet/session.h \
lib/sbuild/chroot/facet/session-clonable.h \
lib/sbuild/chroot/facet/source.h \
@@ -118,6 +119,7 @@ lib_sbuild_public_cc_sources = \
lib/sbuild/chroot/facet/directory-base.cc \
lib/sbuild/chroot/facet/mountable.cc \
lib/sbuild/chroot/facet/personality.cc \
+ lib/sbuild/chroot/facet/plain.cc \
lib/sbuild/chroot/facet/session.cc \
lib/sbuild/chroot/facet/session-clonable.cc \
lib/sbuild/chroot/facet/source.cc \
diff --git a/lib/sbuild/chroot/chroot.cc b/lib/sbuild/chroot/chroot.cc
index cdf2e470..2582cf16 100644
--- a/lib/sbuild/chroot/chroot.cc
+++ b/lib/sbuild/chroot/chroot.cc
@@ -38,6 +38,7 @@
#endif // SBUILD_FEATURE_BTRFSSNAP
#include <sbuild/chroot/facet/facet.h>
#include <sbuild/chroot/facet/personality.h>
+#include <sbuild/chroot/facet/plain.h>
#include <sbuild/chroot/facet/session.h>
#include <sbuild/chroot/facet/session-clonable.h>
#include <sbuild/chroot/facet/source.h>
@@ -106,7 +107,6 @@ namespace sbuild
environment_filter(SBUILD_DEFAULT_ENVIRONMENT_FILTER),
mount_location(),
original(true),
- run_setup_scripts(true),
script_config(),
profile("default"),
command_prefix(),
@@ -136,7 +136,6 @@ namespace sbuild
environment_filter(rhs.environment_filter),
mount_location(rhs.mount_location),
original(rhs.original),
- run_setup_scripts(rhs.run_setup_scripts),
script_config(rhs.script_config),
profile(rhs.profile),
command_prefix(rhs.command_prefix),
@@ -387,13 +386,9 @@ namespace sbuild
bool
chroot::get_run_setup_scripts () const
{
- return this->run_setup_scripts;
- }
+ facet::plain::const_ptr plain = get_facet<facet::plain>();
- void
- chroot::set_run_setup_scripts (bool run_setup_scripts)
- {
- this->run_setup_scripts = run_setup_scripts;
+ return !static_cast<bool>(plain);
}
std::string const&
diff --git a/lib/sbuild/chroot/chroot.h b/lib/sbuild/chroot/chroot.h
index 7293de0f..e8c20951 100644
--- a/lib/sbuild/chroot/chroot.h
+++ b/lib/sbuild/chroot/chroot.h
@@ -404,16 +404,6 @@ namespace sbuild
bool
get_run_setup_scripts () const;
- protected:
- /**
- * Set whether chroot setup scripts will be run.
- *
- * @param run_setup_scripts true if setup scripts will be run,
- * otherwise false.
- */
- void
- set_run_setup_scripts (bool run_setup_scripts);
-
public:
/**
* Get the script configuration file for the chroot. This is a
@@ -864,8 +854,6 @@ namespace sbuild
std::string mount_location;
/// Was the chroot automatically generated?
bool original;
- /// Run chroot setup scripts?
- bool run_setup_scripts;
/// Configuration of the setup and exec scripts.
std::string script_config;
/// Configuration profile for setup scripts (replaces script_config).
diff --git a/lib/sbuild/chroot/facet/directory-base.h b/lib/sbuild/chroot/facet/directory-base.h
index 0fbc5aec..e52366b8 100644
--- a/lib/sbuild/chroot/facet/directory-base.h
+++ b/lib/sbuild/chroot/facet/directory-base.h
@@ -58,10 +58,6 @@ namespace sbuild
/// The destructor.
virtual ~directory_base ();
- protected:
- void
- set_chroot (chroot& chroot);
-
public:
/**
* Get the directory containing the chroot.
@@ -79,9 +75,6 @@ namespace sbuild
void
set_directory (std::string const& directory);
- virtual std::string
- get_path () const;
-
virtual void
setup_env (chroot const& chroot,
environment& env) const;
diff --git a/lib/sbuild/chroot/facet/plain.cc b/lib/sbuild/chroot/facet/plain.cc
index 8ed06c7b..f97904ce 100644
--- a/lib/sbuild/chroot/facet/plain.cc
+++ b/lib/sbuild/chroot/facet/plain.cc
@@ -18,85 +18,74 @@
#include <config.h>
-#include <sbuild/chroot/plain.h>
+#include <sbuild/chroot/facet/plain.h>
#include <sbuild/chroot/facet/session-clonable.h>
#include "format-detail.h"
-#include "lock.h"
+#include "util.h"
+#include <cassert>
#include <cerrno>
+#include <cstring>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/sysmacros.h>
-#include <unistd.h>
+#include <boost/format.hpp>
+using boost::format;
using namespace sbuild;
namespace sbuild
{
namespace chroot
{
-
- plain::plain ():
- directory_base()
- {
- set_run_setup_scripts(false);
-
- remove_facet<facet::session_clonable>();
- }
-
- plain::~plain ()
- {
- }
-
- chroot::ptr
- plain::clone () const
- {
- return ptr(new plain(*this));
- }
-
- chroot::ptr
- plain::clone_session (std::string const& session_id,
- std::string const& alias,
- std::string const& user,
- bool root) const
- {
- return ptr();
- }
-
- chroot::ptr
- plain::clone_source () const
+ namespace facet
{
- return ptr();
- }
- std::string const&
- plain::get_chroot_type () const
- {
- static const std::string type("plain");
+ plain::plain ():
+ directory_base()
+ {
+ }
+
+ plain::~plain ()
+ {
+ }
+
+ plain::plain (const plain& rhs):
+ directory_base(rhs)
+ {
+ }
+
+ void
+ plain::set_chroot (chroot& chroot)
+ {
+ directory_base::set_chroot(chroot);
+ owner->remove_facet<session_clonable>();
+ }
+
+ std::string const&
+ plain::get_name () const
+ {
+ static const std::string name("plain");
+
+ return name;
+ }
+
+ plain::ptr
+ plain::create ()
+ {
+ return ptr(new plain());
+ }
+
+ facet::ptr
+ plain::clone () const
+ {
+ return ptr(new plain(*this));
+ }
+
+ std::string
+ plain::get_path () const
+ {
+ return get_directory();
+ }
- return type;
}
-
- std::string
- plain::get_path () const
- {
- return get_directory();
- }
-
- void
- plain::setup_lock (setup_type type,
- bool lock,
- int status)
- {
- /* By default, plain chroots do no locking. */
- }
-
- chroot::session_flags
- plain::get_session_flags (chroot const& chroot) const
- {
- return SESSION_NOFLAGS;
- }
-
}
}
diff --git a/lib/sbuild/chroot/facet/plain.h b/lib/sbuild/chroot/facet/plain.h
index 98bf2abd..70c938ed 100644
--- a/lib/sbuild/chroot/facet/plain.h
+++ b/lib/sbuild/chroot/facet/plain.h
@@ -16,67 +16,72 @@
*
*********************************************************************/
-#ifndef SBUILD_CHROOT_PLAIN_H
-#define SBUILD_CHROOT_PLAIN_H
+#ifndef SBUILD_CHROOT_FACET_PLAIN_H
+#define SBUILD_CHROOT_FACET_PLAIN_H
-#include <sbuild/chroot/directory-base.h>
+#include <sbuild/config.h>
+#include <sbuild/chroot/facet/directory-base.h>
namespace sbuild
{
namespace chroot
{
-
- /**
- * A chroot located in the filesystem (scripts disabled).
- *
- * This doesn't run any setup scripts and doesn't provide any
- * session support. If you need any of these functions, the
- * directory chroot type is more suited to your needs.
- */
- class plain : public directory_base
+ namespace facet
{
- protected:
- /// The constructor.
- plain ();
- friend class chroot;
+ /**
+ * A chroot stored on an unmounted block device.
+ *
+ * The device will be mounted on demand.
+ */
+ class plain : public directory_base
+ {
+ public:
+ /// A shared_ptr to a chroot facet object.
+ typedef std::shared_ptr<plain> ptr;
+
+ /// A shared_ptr to a const chroot facet object.
+ typedef std::shared_ptr<const plain> const_ptr;
+
+ protected:
+ /// The constructor.
+ plain ();
- public:
- /// The destructor.
- virtual ~plain ();
+ /// The copy constructor.
+ plain (const plain& rhs);
- virtual chroot::ptr
- clone () const;
+ void
+ set_chroot (chroot& chroot);
- virtual chroot::ptr
- clone_session (std::string const& session_id,
- std::string const& alias,
- std::string const& user,
- bool root) const;
+ friend class chroot;
- virtual chroot::ptr
- clone_source () const;
+ public:
+ /// The destructor.
+ virtual ~plain ();
- virtual std::string
- get_path () const;
+ virtual std::string const&
+ get_name () const;
- virtual std::string const&
- get_chroot_type () const;
+ /**
+ * Create a chroot facet.
+ *
+ * @returns a shared_ptr to the new chroot facet.
+ */
+ static ptr
+ create ();
- virtual session_flags
- get_session_flags (chroot const& chroot) const;
+ virtual facet::ptr
+ clone () const;
- protected:
- virtual void
- setup_lock (chroot::setup_type type,
- bool lock,
- int status);
- };
+ virtual std::string
+ get_path () const;
+ };
+ }
}
}
-#endif /* SBUILD_CHROOT_PLAIN_H */
+#endif /* SBUILD_CHROOT_FACET_PLAIN_H */
/*
* Local Variables:
diff --git a/lib/sbuild/chroot/plain.cc b/lib/sbuild/chroot/plain.cc
index 8ed06c7b..2d61f546 100644
--- a/lib/sbuild/chroot/plain.cc
+++ b/lib/sbuild/chroot/plain.cc
@@ -19,7 +19,7 @@
#include <config.h>
#include <sbuild/chroot/plain.h>
-#include <sbuild/chroot/facet/session-clonable.h>
+#include <sbuild/chroot/facet/plain.h>
#include "format-detail.h"
#include "lock.h"
@@ -38,11 +38,9 @@ namespace sbuild
{
plain::plain ():
- directory_base()
+ chroot()
{
- set_run_setup_scripts(false);
-
- remove_facet<facet::session_clonable>();
+ add_facet(facet::plain::create());
}
plain::~plain ()
@@ -70,33 +68,5 @@ namespace sbuild
return ptr();
}
- std::string const&
- plain::get_chroot_type () const
- {
- static const std::string type("plain");
-
- return type;
- }
-
- std::string
- plain::get_path () const
- {
- return get_directory();
- }
-
- void
- plain::setup_lock (setup_type type,
- bool lock,
- int status)
- {
- /* By default, plain chroots do no locking. */
- }
-
- chroot::session_flags
- plain::get_session_flags (chroot const& chroot) const
- {
- return SESSION_NOFLAGS;
- }
-
}
}
diff --git a/lib/sbuild/chroot/plain.h b/lib/sbuild/chroot/plain.h
index 98bf2abd..ad285411 100644
--- a/lib/sbuild/chroot/plain.h
+++ b/lib/sbuild/chroot/plain.h
@@ -19,7 +19,7 @@
#ifndef SBUILD_CHROOT_PLAIN_H
#define SBUILD_CHROOT_PLAIN_H
-#include <sbuild/chroot/directory-base.h>
+#include <sbuild/chroot/chroot.h>
namespace sbuild
{
@@ -33,7 +33,7 @@ namespace sbuild
* session support. If you need any of these functions, the
* directory chroot type is more suited to your needs.
*/
- class plain : public directory_base
+ class plain : public chroot
{
protected:
/// The constructor.
@@ -56,21 +56,6 @@ namespace sbuild
virtual chroot::ptr
clone_source () const;
-
- virtual std::string
- get_path () const;
-
- virtual std::string const&
- get_chroot_type () const;
-
- virtual session_flags
- get_session_flags (chroot const& chroot) const;
-
- protected:
- virtual void
- setup_lock (chroot::setup_type type,
- bool lock,
- int status);
};
}
diff --git a/test/sbuild/chroot/chroot.cc b/test/sbuild/chroot/chroot.cc
index c7341a26..9088f473 100644
--- a/test/sbuild/chroot/chroot.cc
+++ b/test/sbuild/chroot/chroot.cc
@@ -22,6 +22,7 @@
#include <sbuild/keyfile-writer.h>
#include <test/sbuild/chroot/chroot.h>
+#include <test/sbuild/chroot/chroot.h>
#include <algorithm>
#include <set>
@@ -60,12 +61,6 @@ public:
get_chroot_type () const
{ static const std::string type("test"); return type; }
- void
- set_run_setup_scripts (bool run_setup_scripts)
- {
- sbuild::chroot::chroot::set_run_setup_scripts(run_setup_scripts);
- }
-
virtual std::string
get_path () const
{ return get_mount_location(); }
@@ -255,10 +250,6 @@ public:
std::shared_ptr<basic_chroot> c = std::dynamic_pointer_cast<basic_chroot>(chroot);
CPPUNIT_ASSERT(chroot->get_run_setup_scripts() == true);
- c->set_run_setup_scripts(false);
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts() == false);
- c->set_run_setup_scripts(true);
- CPPUNIT_ASSERT(chroot->get_run_setup_scripts() == true);
}
void test_verbose()
diff --git a/test/sbuild/chroot/plain.cc b/test/sbuild/chroot/plain.cc
index 0e9fbdb6..7c536735 100644
--- a/test/sbuild/chroot/plain.cc
+++ b/test/sbuild/chroot/plain.cc
@@ -19,6 +19,7 @@
#include <config.h>
#include <sbuild/config.h>
+#include <sbuild/chroot/facet/plain.h>
#include <sbuild/chroot/plain.h>
#include <sbuild/keyfile-writer.h>
@@ -73,9 +74,10 @@ public:
test_chroot_base<chroot_plain>::setup_chroot_props(chroot);
std::shared_ptr<sbuild::chroot::plain> c = std::dynamic_pointer_cast<sbuild::chroot::plain>(chroot);
-
c->set_mount_location("");
- c->set_directory("/srv/chroot/example-chroot");
+
+ sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
+ plfac->set_directory("/srv/chroot/example-chroot");
}
void
@@ -83,8 +85,9 @@ public:
{
std::shared_ptr<sbuild::chroot::plain> c = std::dynamic_pointer_cast<sbuild::chroot::plain>(chroot);
CPPUNIT_ASSERT(c);
- c->set_directory("/mnt/mount-location/example");
- CPPUNIT_ASSERT(c->get_directory() == "/mnt/mount-location/example");
+ sbuild::chroot::facet::plain::ptr plfac = chroot->get_facet<sbuild::chroot::facet::plain>();
+ plfac->set_directory("/mnt/mount-location/example");
+ CPPUNIT_ASSERT(plfac->get_directory() == "/mnt/mount-location/example");
CPPUNIT_ASSERT(chroot->get_path() == "/mnt/mount-location/example");
CPPUNIT_ASSERT(chroot->get_mount_location() == "");
}