diff options
author | Roger Leigh <rleigh@debian.org> | 2013-05-04 12:52:38 +0100 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2013-05-04 17:17:17 +0100 |
commit | 06947880301773d293d04afcdef63167767c0cb0 (patch) | |
tree | 967ac3064bffa325eab7a4a2227b9e064966b764 | |
parent | 46e7e32d5a8c3a63958919183f4c2f0224bbf8d2 (diff) | |
download | schroot-06947880301773d293d04afcdef63167767c0cb0.tar.gz |
sbuild: Replace clone_session with session_setup facet
33 files changed, 338 insertions, 273 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index b83da780..9cadff99 100644 --- a/lib/sbuild/Makefile.am +++ b/lib/sbuild/Makefile.am @@ -35,6 +35,7 @@ lib_sbuild_public_h_sources = \ lib/sbuild/chroot/facet/plain.h \ lib/sbuild/chroot/facet/session.h \ lib/sbuild/chroot/facet/session-clonable.h \ + lib/sbuild/chroot/facet/session-setup.h \ lib/sbuild/chroot/facet/source.h \ lib/sbuild/chroot/facet/source-clonable.h \ lib/sbuild/chroot/facet/source-setup.h \ @@ -131,6 +132,7 @@ lib_sbuild_public_cc_sources = \ lib/sbuild/chroot/facet/plain.cc \ lib/sbuild/chroot/facet/session.cc \ lib/sbuild/chroot/facet/session-clonable.cc \ + lib/sbuild/chroot/facet/session-setup.cc \ lib/sbuild/chroot/facet/source.cc \ lib/sbuild/chroot/facet/source-clonable.cc \ lib/sbuild/chroot/facet/source-setup.cc \ diff --git a/lib/sbuild/chroot/block-device.cc b/lib/sbuild/chroot/block-device.cc index 9cb62155..084b54fb 100644 --- a/lib/sbuild/chroot/block-device.cc +++ b/lib/sbuild/chroot/block-device.cc @@ -76,21 +76,5 @@ namespace sbuild return ptr(new block_device(*this)); } - chroot::chroot::ptr - block_device::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 block_device(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - } } diff --git a/lib/sbuild/chroot/block-device.h b/lib/sbuild/chroot/block-device.h index 336417d9..fba3ed42 100644 --- a/lib/sbuild/chroot/block-device.h +++ b/lib/sbuild/chroot/block-device.h @@ -62,12 +62,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/btrfs-snapshot.cc b/lib/sbuild/chroot/btrfs-snapshot.cc index fcb9d43f..c820039b 100644 --- a/lib/sbuild/chroot/btrfs-snapshot.cc +++ b/lib/sbuild/chroot/btrfs-snapshot.cc @@ -63,21 +63,5 @@ namespace sbuild return ptr(new btrfs_snapshot(*this)); } - chroot::chroot::ptr - btrfs_snapshot::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 btrfs_snapshot(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - } } diff --git a/lib/sbuild/chroot/btrfs-snapshot.h b/lib/sbuild/chroot/btrfs-snapshot.h index e79b5d24..c215fc5e 100644 --- a/lib/sbuild/chroot/btrfs-snapshot.h +++ b/lib/sbuild/chroot/btrfs-snapshot.h @@ -47,12 +47,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/chroot.cc b/lib/sbuild/chroot/chroot.cc index 0e6b0eac..3c7b70b2 100644 --- a/lib/sbuild/chroot/chroot.cc +++ b/lib/sbuild/chroot/chroot.cc @@ -41,9 +41,10 @@ #include <sbuild/chroot/facet/plain.h> #include <sbuild/chroot/facet/session.h> #include <sbuild/chroot/facet/session-clonable.h> +#include <sbuild/chroot/facet/session-setup.h> +#include <sbuild/chroot/facet/source.h> #include <sbuild/chroot/facet/source-clonable.h> #include <sbuild/chroot/facet/source-setup.h> -#include <sbuild/chroot/facet/source.h> #include <sbuild/chroot/facet/storage.h> #include <sbuild/chroot/facet/userdata.h> #ifdef SBUILD_FEATURE_UNSHARE @@ -209,7 +210,16 @@ namespace sbuild bool root) const { ptr session = 0; - session = clone(); + + facet::session_clonable::const_ptr psrc + (get_facet<facet::session_clonable>()); + if (psrc) + { + + session = psrc->clone_session + (session_id, alias, user, root); + } + return session; } @@ -549,6 +559,18 @@ namespace sbuild throw error(verbosity, VERBOSITY_INVALID); } + chroot::facet_list& + chroot::get_facets () + { + return facets; + } + + const chroot::facet_list& + chroot::get_facets () const + { + return facets; + } + string_list chroot::list_facets () const { diff --git a/lib/sbuild/chroot/chroot.h b/lib/sbuild/chroot/chroot.h index 2d8b2fbc..04c5add9 100644 --- a/lib/sbuild/chroot/chroot.h +++ b/lib/sbuild/chroot/chroot.h @@ -117,6 +117,12 @@ namespace sbuild /// A shared_ptr to a const chroot object. typedef std::shared_ptr<const chroot> const_ptr; + /// A shared pointer to a chroot facet. + typedef std::shared_ptr<facet::facet> facet_ptr; + + /// A list of chroot facets. + typedef std::list<facet_ptr> facet_list; + /// The constructor. chroot (); @@ -152,7 +158,7 @@ namespace sbuild * @param root true if the user has root access, otherwise false. * @returns a session chroot. */ - virtual chroot::ptr + chroot::ptr clone_session (std::string const& session_id, std::string const& alias, std::string const& user, @@ -163,7 +169,7 @@ namespace sbuild * * @returns a source chroot. */ - virtual chroot::ptr + chroot::ptr clone_source () const; /** @@ -609,6 +615,22 @@ namespace sbuild get_facet_strict () const; /** + * Get the list of all chroot facets. + * + * @returns the facet list. + */ + facet_list& + get_facets (); + + /** + * Get the list of all chroot facets. + * + * @returns the facet list. + */ + const facet_list& + get_facets () const; + + /** * Add a chroot facet. * * @param facet the facet to add. @@ -790,10 +812,6 @@ namespace sbuild /// The message verbosity. verbosity message_verbosity; - /// A shared pointer to a chroot facet. - typedef std::shared_ptr<facet::facet> facet_ptr; - /// A list of chroot facets. - typedef std::list<facet_ptr> facet_list; /// Contained chroot facets facet_list facets; }; diff --git a/lib/sbuild/chroot/custom.cc b/lib/sbuild/chroot/custom.cc index 57ed3da3..37addeb8 100644 --- a/lib/sbuild/chroot/custom.cc +++ b/lib/sbuild/chroot/custom.cc @@ -62,21 +62,5 @@ namespace sbuild return ptr(new custom(*this)); } - chroot::chroot::ptr - custom::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 custom(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - } } diff --git a/lib/sbuild/chroot/custom.h b/lib/sbuild/chroot/custom.h index d0655f73..d0ee82ae 100644 --- a/lib/sbuild/chroot/custom.h +++ b/lib/sbuild/chroot/custom.h @@ -53,12 +53,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/directory.cc b/lib/sbuild/chroot/directory.cc index fc8900f0..0f5a00a0 100644 --- a/lib/sbuild/chroot/directory.cc +++ b/lib/sbuild/chroot/directory.cc @@ -76,21 +76,5 @@ namespace sbuild 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; - } - } } diff --git a/lib/sbuild/chroot/directory.h b/lib/sbuild/chroot/directory.h index cffe788b..6e70e160 100644 --- a/lib/sbuild/chroot/directory.h +++ b/lib/sbuild/chroot/directory.h @@ -61,12 +61,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/facet/block-device.cc b/lib/sbuild/chroot/facet/block-device.cc index 7d8eacd2..34b0aa87 100644 --- a/lib/sbuild/chroot/facet/block-device.cc +++ b/lib/sbuild/chroot/facet/block-device.cc @@ -170,7 +170,20 @@ namespace sbuild } } + void + block_device::chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) + { + // Block devices need the mount device name specifying. + mountable::ptr pmnt + (owner->get_facet<mountable>()); + if (pmnt) + pmnt->set_mount_device(get_device()); + } + } } } - diff --git a/lib/sbuild/chroot/facet/block-device.h b/lib/sbuild/chroot/facet/block-device.h index 2da03fdc..453c2f3a 100644 --- a/lib/sbuild/chroot/facet/block-device.h +++ b/lib/sbuild/chroot/facet/block-device.h @@ -22,6 +22,8 @@ #include <sbuild/config.h> #include <sbuild/chroot/facet/block-device-base.h> #include <sbuild/chroot/facet/lvm-snapshot.h> +#include <sbuild/chroot/facet/mountable.h> +#include <sbuild/chroot/facet/session-setup.h> namespace sbuild { @@ -35,7 +37,8 @@ namespace sbuild * * The device will be mounted on demand. */ - class block_device : public block_device_base + class block_device : public block_device_base, + public session_setup { public: /// A shared_ptr to a chroot facet object. @@ -94,6 +97,13 @@ namespace sbuild virtual facet::ptr clone () const; + virtual void + chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root); + protected: virtual void setup_lock (chroot::setup_type type, diff --git a/lib/sbuild/chroot/facet/btrfs-snapshot.cc b/lib/sbuild/chroot/facet/btrfs-snapshot.cc index 3be652f7..47740d91 100644 --- a/lib/sbuild/chroot/facet/btrfs-snapshot.cc +++ b/lib/sbuild/chroot/facet/btrfs-snapshot.cc @@ -274,6 +274,22 @@ namespace sbuild } void + btrfs_snapshot::chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) + { + // Btrfs snapshots need the snapshot name specifying. + if (!get_snapshot_directory().empty()) + { + std::string snapname(get_snapshot_directory()); + snapname += "/" + owner->get_name(); + set_snapshot_name(snapname); + } + } + + void btrfs_snapshot::chroot_source_setup (chroot const& parent) { storage::ptr source_directory(directory::create(*this)); diff --git a/lib/sbuild/chroot/facet/btrfs-snapshot.h b/lib/sbuild/chroot/facet/btrfs-snapshot.h index 2d7407ec..78d5703e 100644 --- a/lib/sbuild/chroot/facet/btrfs-snapshot.h +++ b/lib/sbuild/chroot/facet/btrfs-snapshot.h @@ -21,6 +21,7 @@ #include <sbuild/chroot/chroot.h> #include <sbuild/chroot/facet/storage.h> +#include <sbuild/chroot/facet/session-setup.h> #include <sbuild/chroot/facet/source-setup.h> namespace sbuild @@ -35,7 +36,9 @@ namespace sbuild * * A snapshot subvolume will be created and mounted on demand. */ - class btrfs_snapshot : public storage, public source_setup + class btrfs_snapshot : public storage, + public session_setup, + public source_setup { public: /// Exception type. @@ -162,6 +165,13 @@ namespace sbuild keyfile const& keyfile); virtual void + chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root); + + virtual void chroot_source_setup (chroot const& parent); private: diff --git a/lib/sbuild/chroot/facet/fsunion.cc b/lib/sbuild/chroot/facet/fsunion.cc index bfc6b872..e943ed57 100644 --- a/lib/sbuild/chroot/facet/fsunion.cc +++ b/lib/sbuild/chroot/facet/fsunion.cc @@ -302,6 +302,31 @@ namespace sbuild } void + fsunion::chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) + { + // If the parent did not have a union facet, then neither should we. + fsunion::const_ptr pparentuni(parent.get_facet<fsunion>()); + if (!pparentuni) + { + owner->remove_facet<fsunion>(); + return; + } + + // Filesystem unions need the overlay directory specifying. + std::string overlay = get_union_overlay_directory(); + overlay += "/" + owner->get_name(); + set_union_overlay_directory(overlay); + + std::string underlay = get_union_underlay_directory(); + underlay += "/" + owner->get_name(); + set_union_underlay_directory(underlay); + } + + void fsunion::chroot_source_setup (chroot const& parent) { owner->remove_facet<fsunion>(); diff --git a/lib/sbuild/chroot/facet/fsunion.h b/lib/sbuild/chroot/facet/fsunion.h index 60939aa7..85819193 100644 --- a/lib/sbuild/chroot/facet/fsunion.h +++ b/lib/sbuild/chroot/facet/fsunion.h @@ -22,6 +22,7 @@ #include <sbuild/chroot/chroot.h> #include <sbuild/chroot/facet/facet.h> +#include <sbuild/chroot/facet/session-setup.h> #include <sbuild/chroot/facet/source-setup.h> namespace sbuild @@ -40,7 +41,9 @@ namespace sbuild * directory. The overlay directory and union setup is already * handled. */ - class fsunion : public facet, public source_setup + class fsunion : public facet, + public session_setup, + public source_setup { public: /// Error codes. @@ -188,6 +191,13 @@ namespace sbuild keyfile const& keyfile); virtual void + chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root); + + virtual void chroot_source_setup (chroot const& parent); private: diff --git a/lib/sbuild/chroot/facet/loopback.cc b/lib/sbuild/chroot/facet/loopback.cc index 5795434d..4581a34b 100644 --- a/lib/sbuild/chroot/facet/loopback.cc +++ b/lib/sbuild/chroot/facet/loopback.cc @@ -209,6 +209,20 @@ namespace sbuild keyfile::PRIORITY_REQUIRED); } + void + loopback::chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) + { + // Loopback chroots need the mount device name specifying. + mountable::ptr pmnt + (owner->get_facet<mountable>()); + if (pmnt) + pmnt->set_mount_device(get_filename()); + } + } } } diff --git a/lib/sbuild/chroot/facet/loopback.h b/lib/sbuild/chroot/facet/loopback.h index a9b86bf8..b74cab44 100644 --- a/lib/sbuild/chroot/facet/loopback.h +++ b/lib/sbuild/chroot/facet/loopback.h @@ -20,6 +20,7 @@ #define SBUILD_CHROOT_FACET_LOOPBACK_H #include <sbuild/chroot/chroot.h> +#include <sbuild/chroot/facet/session-setup.h> #include <sbuild/chroot/facet/storage.h> namespace sbuild @@ -34,7 +35,8 @@ namespace sbuild * * The file will be mounted on demand. */ - class loopback : public storage + class loopback : public storage, + public session_setup { public: /// Exception type. @@ -121,6 +123,13 @@ namespace sbuild set_keyfile (chroot& chroot, keyfile const& keyfile); + virtual void + chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root); + private: /// The file to use. std::string filename; diff --git a/lib/sbuild/chroot/facet/lvm-snapshot.cc b/lib/sbuild/chroot/facet/lvm-snapshot.cc index 430e5e08..ffd35e4e 100644 --- a/lib/sbuild/chroot/facet/lvm-snapshot.cc +++ b/lib/sbuild/chroot/facet/lvm-snapshot.cc @@ -268,6 +268,22 @@ namespace sbuild } void + lvm_snapshot::chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) + { + // LVM devices need the snapshot device name specifying. + if (!get_device().empty()) + { + std::string device(dirname(get_device())); + device += "/" + owner->get_name(); + set_snapshot_device(device); + } + } + + void lvm_snapshot::chroot_source_setup (chroot const& parent) { storage::ptr source_block(block_device::create(*this)); diff --git a/lib/sbuild/chroot/facet/lvm-snapshot.h b/lib/sbuild/chroot/facet/lvm-snapshot.h index 2c28481a..03ce39bc 100644 --- a/lib/sbuild/chroot/facet/lvm-snapshot.h +++ b/lib/sbuild/chroot/facet/lvm-snapshot.h @@ -20,6 +20,7 @@ #define SBUILD_CHROOT_FACET_LVM_SNAPSHOT_H #include <sbuild/chroot/facet/block-device-base.h> +#include <sbuild/chroot/facet/session-setup.h> #include <sbuild/chroot/facet/source-setup.h> namespace sbuild @@ -34,7 +35,9 @@ namespace sbuild * * A snapshot LV will be created and mounted on demand. */ - class lvm_snapshot : public block_device_base, public source_setup + class lvm_snapshot : public block_device_base, + public session_setup, + public source_setup { public: /// A shared_ptr to a chroot facet object. @@ -139,6 +142,13 @@ namespace sbuild keyfile const& keyfile); virtual void + chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root); + + virtual void chroot_source_setup (chroot const& parent); private: diff --git a/lib/sbuild/chroot/facet/session-clonable.cc b/lib/sbuild/chroot/facet/session-clonable.cc index 0c581589..aa757bad 100644 --- a/lib/sbuild/chroot/facet/session-clonable.cc +++ b/lib/sbuild/chroot/facet/session-clonable.cc @@ -23,23 +23,12 @@ #include <sbuild/chroot/facet/mountable.h> #include <sbuild/chroot/facet/session.h> #include <sbuild/chroot/facet/session-clonable.h> +#include <sbuild/chroot/facet/session-setup.h> #include <sbuild/chroot/facet/source-clonable.h> #include <sbuild/chroot/plain.h> #ifdef SBUILD_FEATURE_BLOCKDEV #include <sbuild/chroot/facet/block-device-base.h> #endif -#ifdef SBUILD_FEATURE_LVMSNAP -#include <sbuild/chroot/facet/lvm-snapshot.h> -#endif // SBUILD_FEATURE_LVMSNAP -#ifdef SBUILD_FEATURE_LOOPBACK -#include <sbuild/chroot/facet/loopback.h> -#endif // SBUILD_FEATURE_LOOPBACK -#ifdef SBUILD_FEATURE_BTRFSSNAP -#include <sbuild/chroot/facet/btrfs-snapshot.h> -#endif // SBUILD_FEATURE_BTRFSSNAP -#ifdef SBUILD_FEATURE_UNION -#include <sbuild/chroot/facet/fsunion.h> -#endif // SBUILD_FEATURE_UNION #include "format-detail.h" #include <cassert> @@ -100,14 +89,14 @@ namespace sbuild return name; } - void - session_clonable::clone_session_setup (chroot const& parent, - chroot::ptr& clone, - std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const + chroot::ptr + session_clonable::clone_session (std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) const { + chroot::ptr clone = owner->clone(); + // Disable session cloning. clone->remove_facet<session_clonable>(); // Disable source cloning. @@ -168,74 +157,22 @@ namespace sbuild << format("Mount Location: %1%") % clone->get_mount_location() << endl; -#ifdef SBUILD_FEATURE_BLOCKDEV - /* Block devices need the mount device name specifying. */ - /* Note that this will be overridden by LVM snapshot, below, so the - order here is important. */ - std::shared_ptr<block_device_base> blockdevbase(clone->get_facet<block_device_base>()); - if (blockdevbase) - { - mountable::ptr pmnt - (clone->get_facet<mountable>()); - if (pmnt) - pmnt->set_mount_device(blockdevbase->get_device()); - } -#endif // SBUILD_FEATURE_BLOCKDEV - -#ifdef SBUILD_FEATURE_LOOPBACK - /* Loopback chroots need the mount device name specifying. */ - loopback::ptr loop(clone->get_facet<loopback>()); - if (loop) - { - mountable::ptr pmnt - (clone->get_facet<mountable>()); - if (pmnt) - pmnt->set_mount_device(loop->get_filename()); - } -#endif // SBUILD_FEATURE_LOOPBACK + chroot::facet_list& facets = clone->get_facets(); -#ifdef SBUILD_FEATURE_LVMSNAP - /* LVM devices need the snapshot device name specifying. */ - lvm_snapshot::ptr snapshot(clone->get_facet<lvm_snapshot>()); - if (snapshot && !snapshot->get_device().empty()) + for (chroot::facet_list::iterator facet = facets.begin(); + facet != facets.end();) { - std::string device(dirname(snapshot->get_device())); - device += "/" + clone->get_name(); - snapshot->set_snapshot_device(device); + chroot::facet_list::iterator current = facet; + ++facet; + auto setup_facet = std::dynamic_pointer_cast<session_setup>(*current); + if (setup_facet) + { + setup_facet->chroot_session_setup + (*owner, session_id, alias, user, root); + } } -#endif // SBUILD_FEATURE_LVMSNAP -#ifdef SBUILD_FEATURE_BTRFSSNAP - /* Btrfs snapshots need the snapshot name specifying. */ - btrfs_snapshot::ptr btrfs_snap(clone->get_facet<btrfs_snapshot>()); - if (btrfs_snap && !btrfs_snap->get_snapshot_directory().empty()) - { - std::string snapname(btrfs_snap->get_snapshot_directory()); - snapname += "/" + clone->get_name(); - btrfs_snap->set_snapshot_name(snapname); - } -#endif // SBUILD_FEATURE_BTRFSSNAP - -#ifdef SBUILD_FEATURE_UNION - // If the parent did not have a union facet, then neither should we. - fsunion::const_ptr pparentuni(parent.get_facet<fsunion>()); - if (!pparentuni) - clone->remove_facet<fsunion>(); - - /* Filesystem unions need the overlay directory specifying. */ - fsunion::ptr puni(clone->get_facet<fsunion>()); - - if (puni) - { - std::string overlay = puni->get_union_overlay_directory(); - overlay += "/" + clone->get_name(); - puni->set_union_overlay_directory(overlay); - - std::string underlay = puni->get_union_underlay_directory(); - underlay += "/" + clone->get_name(); - puni->set_union_underlay_directory(underlay); - } -#endif // SBUILD_FEATURE_UNION + return clone; } chroot::session_flags diff --git a/lib/sbuild/chroot/facet/session-clonable.h b/lib/sbuild/chroot/facet/session-clonable.h index 47eacdbc..b5c3a8a1 100644 --- a/lib/sbuild/chroot/facet/session-clonable.h +++ b/lib/sbuild/chroot/facet/session-clonable.h @@ -75,13 +75,11 @@ namespace sbuild * @param user the user creating the session. * @param root whether or not the user is switching to root. */ - virtual void - clone_session_setup (chroot const& parent, - chroot::ptr& clone, - std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; + virtual chroot::ptr + clone_session (std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) const; virtual chroot::session_flags get_session_flags (chroot const& chroot) const; diff --git a/lib/sbuild/chroot/facet/session-setup.cc b/lib/sbuild/chroot/facet/session-setup.cc new file mode 100644 index 00000000..af389c6b --- /dev/null +++ b/lib/sbuild/chroot/facet/session-setup.cc @@ -0,0 +1,38 @@ +/* Copyright © 2005-2013 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 <sbuild/chroot/facet/session-setup.h> + +namespace sbuild +{ + namespace chroot + { + namespace facet + { + + session_setup::session_setup () + { + } + + session_setup::~session_setup () + { + } + + } + } +} diff --git a/lib/sbuild/chroot/facet/session-setup.h b/lib/sbuild/chroot/facet/session-setup.h new file mode 100644 index 00000000..7451f48f --- /dev/null +++ b/lib/sbuild/chroot/facet/session-setup.h @@ -0,0 +1,86 @@ +/* Copyright © 2005-2013 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_FACET_SESSION_SETUP_H +#define SBUILD_CHROOT_FACET_SESSION_SETUP_H + +#include <sbuild/chroot/chroot.h> + +#include <memory> +#include <string> + +namespace sbuild +{ + namespace chroot + { + namespace facet + { + + /** + * 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. + */ + class session_setup + { + public: + /// A shared_ptr to a chroot session_setup object. + typedef std::shared_ptr<session_setup> ptr; + + /// A shared_ptr to a const chroot session_setup object. + typedef std::shared_ptr<const session_setup> const_ptr; + + protected: + /// The constructor. + session_setup (); + + public: + /// The destructor. + virtual ~session_setup (); + + /** + * Set up a newly-cloned session chroot. + * + * @param parent the parent of the cloned chroot. + * @param session_id the identifier (session_id) for the new session. + * @param alias used to initially identify the chroot. + * @param user the user creating the session. + * @param root true if the user has root access, otherwise false. + */ + virtual void + chroot_session_setup (chroot const& parent, + std::string const& session_id, + std::string const& alias, + std::string const& user, + bool root) = 0; + + }; + + } + } +} + +#endif /* SBUILD_CHROOT_FACET_SESSION_SETUP_H */ + +/* + * Local Variables: + * mode:C++ + * End: + */ diff --git a/lib/sbuild/chroot/file.cc b/lib/sbuild/chroot/file.cc index fd85a5e3..c3bd5a7e 100644 --- a/lib/sbuild/chroot/file.cc +++ b/lib/sbuild/chroot/file.cc @@ -63,21 +63,5 @@ namespace sbuild return ptr(new file(*this)); } - chroot::chroot::ptr - file::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 file(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - } } diff --git a/lib/sbuild/chroot/file.h b/lib/sbuild/chroot/file.h index 7cfa4a52..a5963a58 100644 --- a/lib/sbuild/chroot/file.h +++ b/lib/sbuild/chroot/file.h @@ -48,12 +48,6 @@ namespace sbuild virtual chroot::chroot::ptr clone () const; - - virtual chroot::chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/loopback.cc b/lib/sbuild/chroot/loopback.cc index 43e3c26f..e7c8482c 100644 --- a/lib/sbuild/chroot/loopback.cc +++ b/lib/sbuild/chroot/loopback.cc @@ -67,21 +67,5 @@ namespace sbuild return ptr(new loopback(*this)); } - chroot::chroot::ptr - loopback::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 loopback(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - } } diff --git a/lib/sbuild/chroot/loopback.h b/lib/sbuild/chroot/loopback.h index 92928401..49e7adcf 100644 --- a/lib/sbuild/chroot/loopback.h +++ b/lib/sbuild/chroot/loopback.h @@ -52,12 +52,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/lvm-snapshot.cc b/lib/sbuild/chroot/lvm-snapshot.cc index c31b652f..7284a6c9 100644 --- a/lib/sbuild/chroot/lvm-snapshot.cc +++ b/lib/sbuild/chroot/lvm-snapshot.cc @@ -63,21 +63,5 @@ namespace sbuild return ptr(new lvm_snapshot(*this)); } - chroot::chroot::ptr - lvm_snapshot::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 lvm_snapshot(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; - } - } } diff --git a/lib/sbuild/chroot/lvm-snapshot.h b/lib/sbuild/chroot/lvm-snapshot.h index c9da746e..b2a8a698 100644 --- a/lib/sbuild/chroot/lvm-snapshot.h +++ b/lib/sbuild/chroot/lvm-snapshot.h @@ -48,12 +48,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } diff --git a/lib/sbuild/chroot/plain.cc b/lib/sbuild/chroot/plain.cc index 59882605..6dd2e8da 100644 --- a/lib/sbuild/chroot/plain.cc +++ b/lib/sbuild/chroot/plain.cc @@ -54,14 +54,5 @@ namespace sbuild 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(); - } - } } diff --git a/lib/sbuild/chroot/plain.h b/lib/sbuild/chroot/plain.h index 810cab55..87f4ffb5 100644 --- a/lib/sbuild/chroot/plain.h +++ b/lib/sbuild/chroot/plain.h @@ -47,12 +47,6 @@ namespace sbuild virtual chroot::ptr clone () const; - - virtual chroot::ptr - clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const; }; } |