summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRoger Leigh <rleigh@debian.org>2013-04-28 12:27:20 +0100
committerRoger Leigh <rleigh@debian.org>2013-05-04 17:17:17 +0100
commit621574f3b5a314dff4cd15d766bbe84bec29d22e (patch)
tree5d4f21ede6424c1ff13745816140834add418775 /lib
parentdc6bdbc920d8b3e141447453aeeecd6970cd68d2 (diff)
downloadschroot-621574f3b5a314dff4cd15d766bbe84bec29d22e.tar.gz
sbuild::chroot: Migrate directory to storage facet
Diffstat (limited to 'lib')
-rw-r--r--lib/sbuild/Makefile.am2
-rw-r--r--lib/sbuild/chroot/directory.cc88
-rw-r--r--lib/sbuild/chroot/directory.h38
-rw-r--r--lib/sbuild/chroot/facet/directory.cc211
-rw-r--r--lib/sbuild/chroot/facet/directory.h137
5 files changed, 158 insertions, 318 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am
index 986571a7..b23c5300 100644
--- a/lib/sbuild/Makefile.am
+++ b/lib/sbuild/Makefile.am
@@ -27,6 +27,7 @@ lib_sbuild_public_h_sources = \
lib/sbuild/chroot/directory-base.h \
lib/sbuild/chroot/facet/btrfs-snapshot.cc \
lib/sbuild/chroot/facet/facet.h \
+ lib/sbuild/chroot/facet/directory.h \
lib/sbuild/chroot/facet/directory-base.h \
lib/sbuild/chroot/facet/mountable.h \
lib/sbuild/chroot/facet/personality.h \
@@ -117,6 +118,7 @@ lib_sbuild_public_cc_sources = \
lib/sbuild/chroot/directory.cc \
lib/sbuild/chroot/directory-base.cc \
lib/sbuild/chroot/facet/btrfs-snapshot.cc \
+ lib/sbuild/chroot/facet/directory.cc \
lib/sbuild/chroot/facet/facet.cc \
lib/sbuild/chroot/facet/directory-base.cc \
lib/sbuild/chroot/facet/mountable.cc \
diff --git a/lib/sbuild/chroot/directory.cc b/lib/sbuild/chroot/directory.cc
index b1037954..726c38aa 100644
--- a/lib/sbuild/chroot/directory.cc
+++ b/lib/sbuild/chroot/directory.cc
@@ -19,6 +19,8 @@
#include <config.h>
#include <sbuild/chroot/directory.h>
+#include <sbuild/chroot/facet/btrfs-snapshot.h>
+#include <sbuild/chroot/facet/directory.h>
#include <sbuild/chroot/facet/session.h>
#include <sbuild/chroot/facet/session-clonable.h>
#include <sbuild/chroot/facet/source-clonable.h>
@@ -44,28 +46,22 @@ namespace sbuild
{
directory::directory ():
- directory_base()
+ chroot()
{
-#ifdef SBUILD_FEATURE_UNION
- add_facet(facet::fsunion::create());
-#endif // SBUILD_FEATURE_UNION
+ add_facet(facet::directory::create());
}
directory::directory (const directory& rhs):
- directory_base(rhs)
+ chroot(rhs)
{
}
#ifdef SBUILD_FEATURE_BTRFSSNAP
directory::directory (const btrfs_snapshot& rhs):
- directory_base(rhs)
+ chroot(rhs)
{
-#ifdef SBUILD_FEATURE_UNION
- if (!get_facet<facet::fsunion>())
- add_facet(facet::fsunion::create());
-#endif // SBUILD_FEATURE_UNION
-
- set_directory(rhs.get_source_subvolume());
+ facet::storage::ptr dir = facet::directory::create(*get_facet_strict<facet::btrfs_snapshot>());
+ replace_facet<facet::storage>(dir);
}
#endif // SBUILD_FEATURE_BTRFSSNAP
@@ -109,73 +105,5 @@ namespace sbuild
return clone;
}
- std::string
- directory::get_path () const
- {
- return get_mount_location();
- }
-
- void
- directory::setup_env (chroot const& chroot,
- environment& env) const
- {
- directory_base::setup_env(chroot, env);
- }
-
- std::string const&
- directory::get_chroot_type () const
- {
- static const std::string type("directory");
-
- return type;
- }
-
- void
- directory::setup_lock (setup_type type,
- bool lock,
- int status)
- {
- /* Create or unlink session information. */
- if ((type == SETUP_START && lock == true) ||
- (type == SETUP_STOP && lock == false && status == 0))
- {
- bool start = (type == SETUP_START);
- get_facet_strict<facet::session>()->setup_session_info(start);
- }
- }
-
- chroot::session_flags
- directory::get_session_flags (chroot const& chroot) const
- {
- return SESSION_NOFLAGS;
- }
-
- void
- directory::get_details (chroot const& chroot,
- format_detail& detail) const
- {
- directory_base::get_details(chroot, detail);
- }
-
- void
- directory::get_used_keys (string_list& used_keys) const
- {
- directory_base::get_used_keys(used_keys);
- }
-
- void
- directory::get_keyfile (chroot const& chroot,
- keyfile& keyfile) const
- {
- directory_base::get_keyfile(chroot, keyfile);
- }
-
- void
- directory::set_keyfile (chroot& chroot,
- keyfile const& keyfile)
- {
- directory_base::set_keyfile(chroot, keyfile);
- }
-
}
}
diff --git a/lib/sbuild/chroot/directory.h b/lib/sbuild/chroot/directory.h
index 1c414880..c3670728 100644
--- a/lib/sbuild/chroot/directory.h
+++ b/lib/sbuild/chroot/directory.h
@@ -20,7 +20,7 @@
#define SBUILD_CHROOT_DIRECTORY_H
#include <sbuild/config.h>
-#include <sbuild/chroot/directory-base.h>
+#include <sbuild/chroot/chroot.h>
#ifdef SBUILD_FEATURE_BTRFSSNAP
#include <sbuild/chroot/btrfs-snapshot.h>
#endif
@@ -36,7 +36,7 @@ namespace sbuild
* It runs setup scripts and can provide multiple sessions
* using the union facet.
*/
- class directory : public directory_base
+ class directory : public chroot
{
protected:
/// The constructor.
@@ -70,40 +70,6 @@ namespace sbuild
virtual chroot::ptr
clone_source () const;
-
- virtual std::string
- get_path () const;
-
- virtual void
- setup_env (chroot const& chroot,
- environment& env) 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);
-
- virtual void
- get_details (chroot const& chroot,
- format_detail& detail) const;
-
- virtual void
- get_used_keys (string_list& used_keys) const;
-
- virtual void
- get_keyfile (chroot const& chroot,
- keyfile& keyfile) const;
-
- virtual void
- set_keyfile (chroot& chroot,
- keyfile const& keyfile);
};
}
diff --git a/lib/sbuild/chroot/facet/directory.cc b/lib/sbuild/chroot/facet/directory.cc
index ed8d70e9..81dc297a 100644
--- a/lib/sbuild/chroot/facet/directory.cc
+++ b/lib/sbuild/chroot/facet/directory.cc
@@ -18,163 +18,108 @@
#include <config.h>
-#include <sbuild/chroot/directory.h>
-#include <sbuild/chroot/facet/session-clonable.h>
-#include <sbuild/chroot/facet/source-clonable.h>
-#ifdef SBUILD_FEATURE_UNION
+#include <sbuild/chroot/facet/directory.h>
#include <sbuild/chroot/facet/fsunion.h>
-#endif // SBUILD_FEATURE_UNION
+#include <sbuild/chroot/facet/session.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
{
-
- directory::directory ():
- directory_base()
+ namespace facet
{
-#ifdef SBUILD_FEATURE_UNION
- add_facet(facet::fsunion::create());
-#endif // SBUILD_FEATURE_UNION
- }
- directory::directory (const directory& rhs):
- directory_base(rhs)
- {
- }
-
-#ifdef SBUILD_FEATURE_BTRFSSNAP
- directory::directory (const btrfs_snapshot& rhs):
- directory_base(rhs)
- {
-#ifdef SBUILD_FEATURE_UNION
- if (!get_facet<facet::fsunion>())
- add_facet(facet::fsunion::create());
-#endif // SBUILD_FEATURE_UNION
-
- set_directory(rhs.get_source_subvolume());
- }
-#endif // SBUILD_FEATURE_BTRFSSNAP
-
- directory::~directory ()
- {
- }
-
- chroot::ptr
- directory::clone () const
- {
- return ptr(new directory(*this));
- }
-
- chroot::ptr
- directory::clone_session (std::string const& session_id,
- std::string const& alias,
- std::string const& user,
- bool root) const
- {
- facet::session_clonable::const_ptr psess
- (get_facet<facet::session_clonable>());
- assert(psess);
-
- ptr session(new directory(*this));
- psess->clone_session_setup(*this, session, session_id, alias, user, root);
-
- return session;
- }
-
- chroot::ptr
- directory::clone_source () const
- {
- ptr clone(new directory(*this));
+ directory::directory ():
+ directory_base()
+ {
+ }
- facet::source_clonable::const_ptr psrc
- (get_facet<facet::source_clonable>());
- assert(psrc);
+ directory::~directory ()
+ {
+ }
- psrc->clone_source_setup(*this, clone);
+ directory::directory (const directory& rhs):
+ directory_base(rhs)
+ {
+ }
- return clone;
- }
-
- std::string
- directory::get_path () const
- {
- return get_mount_location();
- }
-
- void
- directory::setup_env (chroot const& chroot,
- environment& env) const
- {
- directory_base::setup_env(chroot, env);
- }
-
- std::string const&
- directory::get_chroot_type () const
- {
- static const std::string type("directory");
-
- return type;
- }
+#ifdef SBUILD_FEATURE_BTRFSSNAP
+ directory::directory (const btrfs_snapshot& rhs):
+ directory_base()
+ {
+ set_directory(rhs.get_source_subvolume());
+ }
+#endif // SBUILD_FEATURE_BTRFSSNAP
- void
- directory::setup_lock (setup_type type,
- bool lock,
- int status)
- {
- /* Create or unlink session information. */
- if ((type == SETUP_START && lock == true) ||
- (type == SETUP_STOP && lock == false && status == 0))
- {
- bool start = (type == SETUP_START);
- setup_session_info(start);
- }
- }
+ void
+ directory::set_chroot (chroot& chroot)
+ {
+ directory_base::set_chroot(chroot);
+#ifdef SBUILD_FEATURE_UNION
+ if (!owner->get_facet<fsunion>())
+ owner->add_facet(fsunion::create());
+#endif // SBUILD_FEATURE_UNION
+ }
- chroot::session_flags
- directory::get_session_flags (chroot const& chroot) const
- {
- return SESSION_NOFLAGS;
- }
+ std::string const&
+ directory::get_name () const
+ {
+ static const std::string name("directory");
- void
- directory::get_details (chroot const& chroot,
- format_detail& detail) const
- {
- directory_base::get_details(chroot, detail);
- }
+ return name;
+ }
- void
- directory::get_used_keys (string_list& used_keys) const
- {
- directory_base::get_used_keys(used_keys);
- }
+ directory::ptr
+ directory::create ()
+ {
+ return ptr(new directory());
+ }
- void
- directory::get_keyfile (chroot const& chroot,
- keyfile& keyfile) const
- {
- directory_base::get_keyfile(chroot, keyfile);
- }
+#ifdef SBUILD_FEATURE_BTRFSSNAP
+ directory::ptr
+ directory::create (const btrfs_snapshot& rhs)
+ {
+ return ptr(new directory(rhs));
+ }
+ #endif // SBUILD_FEATURE_BTRFSSNAP
+
+ facet::ptr
+ directory::clone () const
+ {
+ return ptr(new directory(*this));
+ }
+
+ std::string
+ directory::get_path () const
+ {
+ return owner->get_mount_location();
+ }
+
+ void
+ directory::setup_lock (chroot::setup_type type,
+ bool lock,
+ int status)
+ {
+ /* Create or unlink session information. */
+ if ((type == chroot::SETUP_START && lock == true) ||
+ (type == chroot::SETUP_STOP && lock == false && status == 0))
+ {
+ bool start = (type == chroot::SETUP_START);
+ owner->get_facet_strict<session>()->setup_session_info(start);
+ }
+ }
- void
- directory::set_keyfile (chroot& chroot,
- keyfile const& keyfile)
- {
- directory_base::set_keyfile(chroot, keyfile);
}
-
}
}
diff --git a/lib/sbuild/chroot/facet/directory.h b/lib/sbuild/chroot/facet/directory.h
index 1c414880..c41bc40a 100644
--- a/lib/sbuild/chroot/facet/directory.h
+++ b/lib/sbuild/chroot/facet/directory.h
@@ -16,100 +16,99 @@
*
*********************************************************************/
-#ifndef SBUILD_CHROOT_DIRECTORY_H
-#define SBUILD_CHROOT_DIRECTORY_H
+#ifndef SBUILD_CHROOT_FACET_DIRECTORY_H
+#define SBUILD_CHROOT_FACET_DIRECTORY_H
#include <sbuild/config.h>
-#include <sbuild/chroot/directory-base.h>
+#include <sbuild/chroot/facet/directory-base.h>
#ifdef SBUILD_FEATURE_BTRFSSNAP
-#include <sbuild/chroot/btrfs-snapshot.h>
+#include <sbuild/chroot/facet/btrfs-snapshot.h>
#endif
namespace sbuild
{
namespace chroot
{
-
- /**
- * A chroot located in the filesystem.
- *
- * It runs setup scripts and can provide multiple sessions
- * using the union facet.
- */
- class directory : public directory_base
+ namespace facet
{
- protected:
- /// The constructor.
- directory ();
- /// The copy constructor.
- directory (const directory& rhs);
+ /**
+ * A chroot stored on an unmounted block device.
+ *
+ * The device will be mounted on demand.
+ */
+ class directory : public directory_base
+ {
+ public:
+ /// A shared_ptr to a chroot facet object.
+ typedef std::shared_ptr<directory> ptr;
+
+ /// A shared_ptr to a const chroot facet object.
+ typedef std::shared_ptr<const directory> const_ptr;
+
+ protected:
+ /// The constructor.
+ directory ();
+
+ /// The copy constructor.
+ directory (const directory& rhs);
#ifdef SBUILD_FEATURE_BTRFSSNAP
/// The copy constructor.
directory (const btrfs_snapshot& rhs);
-#endif
+#endif // SBUILD_FEATURE_BTRFSSNAP
+
+ void
+ set_chroot (chroot& chroot);
- friend class chroot;
+ friend class chroot;
#ifdef SBUILD_FEATURE_BTRFSSNAP
friend class btrfs_snapshot;
-#endif
-
- public:
- /// The destructor.
- virtual ~directory ();
-
- virtual chroot::ptr
- clone () const;
+#endif // SBUILD_FEATURE_BTRFSSNAP
- virtual chroot::ptr
- clone_session (std::string const& session_id,
- std::string const& alias,
- std::string const& user,
- bool root) const;
+ public:
+ /// The destructor.
+ virtual ~directory ();
- virtual chroot::ptr
- clone_source () const;
+ virtual std::string const&
+ get_name () const;
- virtual std::string
- get_path () const;
-
- virtual void
- setup_env (chroot const& chroot,
- environment& env) 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);
-
- virtual void
- get_details (chroot const& chroot,
- format_detail& detail) const;
-
- virtual void
- get_used_keys (string_list& used_keys) const;
-
- virtual void
- get_keyfile (chroot const& chroot,
- keyfile& keyfile) const;
-
- virtual void
- set_keyfile (chroot& chroot,
- keyfile const& keyfile);
- };
+ /**
+ * Create a chroot facet.
+ *
+ * @returns a shared_ptr to the new chroot facet.
+ */
+ static ptr
+ create ();
+#ifdef SBUILD_FEATURE_BTRFSSNAP
+ /**
+ * Create a chroot facet from a btrfs snapshot.
+ *
+ * @returns a shared_ptr to the new chroot facet.
+ */
+ static ptr
+ create (const btrfs_snapshot& rhs);
+ #endif // SBUILD_FEATURE_BTRFSSNAP
+
+ virtual facet::ptr
+ clone () const;
+
+ virtual std::string
+ get_path () const;
+
+ protected:
+ virtual void
+ setup_lock (chroot::setup_type type,
+ bool lock,
+ int status);
+ };
+
+ }
}
}
-#endif /* SBUILD_CHROOT_DIRECTORY_H */
+#endif /* SBUILD_CHROOT_FACET_DIRECTORY_H */
/*
* Local Variables: