diff options
-rw-r--r-- | lib/sbuild/Makefile.am | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot-btrfs-snapshot.cc | 268 | ||||
-rw-r--r-- | lib/sbuild/chroot-btrfs-snapshot.h | 162 | ||||
-rw-r--r-- | lib/sbuild/chroot-facet-session-clonable.cc | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot/btrfs-snapshot.cc | 276 | ||||
-rw-r--r-- | lib/sbuild/chroot/btrfs-snapshot.h | 164 | ||||
-rw-r--r-- | lib/sbuild/chroot/chroot.cc | 4 | ||||
-rw-r--r-- | lib/sbuild/chroot/directory.cc | 2 | ||||
-rw-r--r-- | lib/sbuild/chroot/directory.h | 8 | ||||
-rw-r--r-- | test/sbuild/chroot-btrfs-snapshot.cc | 22 |
10 files changed, 463 insertions, 451 deletions
diff --git a/lib/sbuild/Makefile.am b/lib/sbuild/Makefile.am index 7fc0a818..07de2197 100644 --- a/lib/sbuild/Makefile.am +++ b/lib/sbuild/Makefile.am @@ -85,7 +85,7 @@ endif if BUILD_BTRFSSNAP lib_sbuild_public_btrfssnap_h_sources = \ - lib/sbuild/chroot-btrfs-snapshot.h + lib/sbuild/chroot/btrfs-snapshot.h endif if BUILD_LOOPBACK @@ -162,7 +162,7 @@ endif if BUILD_BTRFSSNAP lib_sbuild_public_btrfssnap_cc_sources = \ - lib/sbuild/chroot-btrfs-snapshot.cc + lib/sbuild/chroot/btrfs-snapshot.cc endif if BUILD_LOOPBACK diff --git a/lib/sbuild/chroot-btrfs-snapshot.cc b/lib/sbuild/chroot-btrfs-snapshot.cc deleted file mode 100644 index b8cb7d3e..00000000 --- a/lib/sbuild/chroot-btrfs-snapshot.cc +++ /dev/null @@ -1,268 +0,0 @@ -/* 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 <config.h> - -#include "chroot-btrfs-snapshot.h" -#include <sbuild/chroot/directory.h> -#include "chroot-facet-session.h" -#include "chroot-facet-session-clonable.h" -#include "chroot-facet-source-clonable.h" -#include "format-detail.h" -#include "lock.h" - -#include <cassert> -#include <cerrno> - -#include <boost/format.hpp> - -using std::endl; -using boost::format; -using namespace sbuild; - -chroot_btrfs_snapshot::chroot_btrfs_snapshot (): - chroot(), - source_subvolume(), - snapshot_directory(), - snapshot_name() -{ - add_facet(chroot_facet_source_clonable::create()); -} - -chroot_btrfs_snapshot::chroot_btrfs_snapshot (const chroot_btrfs_snapshot& rhs): - chroot(rhs), - source_subvolume(rhs.source_subvolume), - snapshot_directory(rhs.snapshot_directory), - snapshot_name(rhs.snapshot_name) -{ -} - -chroot_btrfs_snapshot::~chroot_btrfs_snapshot () -{ -} - -chroot::chroot::ptr -chroot_btrfs_snapshot::clone () const -{ - return ptr(new chroot_btrfs_snapshot(*this)); -} - -chroot::chroot::ptr -chroot_btrfs_snapshot::clone_session (std::string const& session_id, - std::string const& alias, - std::string const& user, - bool root) const -{ - chroot_facet_session_clonable::const_ptr psess - (get_facet<chroot_facet_session_clonable>()); - assert(psess); - - ptr session(new chroot_btrfs_snapshot(*this)); - psess->clone_session_setup(*this, session, session_id, alias, user, root); - - return session; -} - -chroot::chroot::ptr -chroot_btrfs_snapshot::clone_source () const -{ - ptr clone(new sbuild::chroot::directory(*this)); - - chroot_facet_source_clonable::const_ptr psrc - (get_facet<chroot_facet_source_clonable>()); - assert(psrc); - - psrc->clone_source_setup(*this, clone); - - return clone; -} - -std::string const& -chroot_btrfs_snapshot::get_source_subvolume () const -{ - return this->source_subvolume; -} - -void -chroot_btrfs_snapshot::set_source_subvolume (std::string const& source_subvolume) -{ - if (!is_absname(source_subvolume)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->source_subvolume = source_subvolume; -} - -std::string const& -chroot_btrfs_snapshot::get_snapshot_directory () const -{ - return this->snapshot_directory; -} - -void -chroot_btrfs_snapshot::set_snapshot_directory (std::string const& snapshot_directory) -{ - if (!is_absname(snapshot_directory)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->snapshot_directory = snapshot_directory; -} - -std::string const& -chroot_btrfs_snapshot::get_snapshot_name () const -{ - return this->snapshot_name; -} - -void -chroot_btrfs_snapshot::set_snapshot_name (std::string const& snapshot_name) -{ - if (!is_absname(snapshot_name)) - throw error(source_subvolume, DIRECTORY_ABS); - - this->snapshot_name = snapshot_name; -} - -std::string const& -chroot_btrfs_snapshot::get_chroot_type () const -{ - static const std::string type("btrfs-snapshot"); - - return type; -} - -std::string -chroot_btrfs_snapshot::get_path () const -{ - return get_mount_location(); -} - -void -chroot_btrfs_snapshot::setup_env (chroot const& chroot, - environment& env) const -{ - chroot::setup_env(chroot, env); - - env.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", get_source_subvolume()); - env.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", get_snapshot_directory()); - env.add("CHROOT_BTRFS_SNAPSHOT_NAME", get_snapshot_name()); -} - -void -chroot_btrfs_snapshot::setup_lock (chroot::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); - } -} - -chroot::chroot::session_flags -chroot_btrfs_snapshot::get_session_flags (chroot const& chroot) const -{ - session_flags flags = SESSION_NOFLAGS; - - if (get_facet<chroot_facet_session>()) - flags = flags | SESSION_PURGE; - - return flags; -} - -void -chroot_btrfs_snapshot::get_details (chroot const& chroot, - format_detail& detail) const -{ - chroot::get_details(chroot, detail); - - if (!this->get_source_subvolume().empty()) - detail.add(_("Btrfs Source Subvolume"), get_source_subvolume()); - if (!this->get_snapshot_directory().empty()) - detail.add(_("Btrfs Snapshot Directory"), get_snapshot_directory()); - if (!this->get_snapshot_name().empty()) - detail.add(_("Btrfs Snapshot Name"), get_snapshot_name()); -} - -void -chroot_btrfs_snapshot::get_used_keys (string_list& used_keys) const -{ - chroot::get_used_keys(used_keys); - - used_keys.push_back("btrfs-source-subvolume"); - used_keys.push_back("btrfs-snapshot-directory"); - used_keys.push_back("btrfs-snapshot-name"); -} - -void -chroot_btrfs_snapshot::get_keyfile (chroot const& chroot, - keyfile& keyfile) const -{ - chroot::get_keyfile(chroot, keyfile); - - bool session = static_cast<bool>(get_facet<chroot_facet_session>()); - - if (!session) - keyfile::set_object_value(*this, - &chroot_btrfs_snapshot::get_source_subvolume, - keyfile, get_name(), - "btrfs-source-subvolume"); - - if (!session) - keyfile::set_object_value(*this, - &chroot_btrfs_snapshot::get_snapshot_directory, - keyfile, get_name(), - "btrfs-snapshot-directory"); - - if (session) - keyfile::set_object_value(*this, - &chroot_btrfs_snapshot::get_snapshot_name, - keyfile, get_name(), - "btrfs-snapshot-name"); -} - -void -chroot_btrfs_snapshot::set_keyfile (chroot& chroot, - keyfile const& keyfile) -{ - chroot::set_keyfile(chroot, keyfile); - - bool session = static_cast<bool>(get_facet<chroot_facet_session>()); - - keyfile::get_object_value(*this, &chroot_btrfs_snapshot::set_source_subvolume, - keyfile, get_name(), "btrfs-source-subvolume", - session ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_REQUIRED - ); // Only needed for creating snapshot, not using snapshot - - keyfile::get_object_value(*this, &chroot_btrfs_snapshot::set_snapshot_directory, - keyfile, get_name(), "btrfs-snapshot-directory", - session ? - keyfile::PRIORITY_DISALLOWED : - keyfile::PRIORITY_REQUIRED - ); // Only needed for creating snapshot, not using snapshot - - keyfile::get_object_value(*this, &chroot_btrfs_snapshot::set_snapshot_name, - keyfile, get_name(), "btrfs-snapshot-name", - session ? - keyfile::PRIORITY_REQUIRED : - keyfile::PRIORITY_DISALLOWED); -} diff --git a/lib/sbuild/chroot-btrfs-snapshot.h b/lib/sbuild/chroot-btrfs-snapshot.h deleted file mode 100644 index 873287b6..00000000 --- a/lib/sbuild/chroot-btrfs-snapshot.h +++ /dev/null @@ -1,162 +0,0 @@ -/* 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_BTRFS_SNAPSHOT_H -#define SBUILD_CHROOT_BTRFS_SNAPSHOT_H - -#include <sbuild/chroot/chroot.h> - -namespace sbuild -{ - - /** - * A chroot stored on an BTRFS logical volume (LV). - * - * A snapshot LV will be created and mounted on demand. - */ - class chroot_btrfs_snapshot : public chroot::chroot - { - protected: - /// The constructor. - chroot_btrfs_snapshot (); - - /// The copy constructor. - chroot_btrfs_snapshot (const chroot_btrfs_snapshot& rhs); - - friend class chroot; - - public: - /// The destructor. - virtual ~chroot_btrfs_snapshot (); - - 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; - - virtual chroot::ptr - clone_source () const; - - /** - * Get the source subvolume path. This is used by "btrfs - * subvolume snapshot". - * - * @returns the source subvolume. - */ - std::string const& - get_source_subvolume () const; - - /** - * Set the source subvolume path. This is used by "btrfs - * subvolume snapshot". - * - * @param source_subvolume the source subvolume. - */ - void - set_source_subvolume (std::string const& source_subvolume); - - /** - * Get the snapshot directory. - * - * @returns the directory. - */ - std::string const& - get_snapshot_directory () const; - - /** - * Set the snapshot directory. - * - * @param snapshot_directory the snapshot directory. - */ - void - set_snapshot_directory (std::string const& snapshot_directory); - - /** - * Get the snapshot name. This is used by "btrfs subvolume - * snapshot", and is the full path to the snapshot. - * - * @returns the name. - */ - std::string const& - get_snapshot_name () const; - - /** - * Set the snapshot name. This is used by "btrfs subvolume - * snapshot", and is the full path to the snapshot. - * - * @param snapshot_name the snapshot name. - */ - void - set_snapshot_name (std::string const& snapshot_name); - - virtual std::string const& - get_chroot_type () const; - - virtual std::string - get_path () const; - - virtual void - setup_env (chroot const& chroot, - environment& env) 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); - - private: - /// Btrfs source subvolume - std::string source_subvolume; - /// Btrfs snapshot path - std::string snapshot_directory; - /// Btrfs snapshot name - std::string snapshot_name; - }; - -} - -#endif /* SBUILD_CHROOT_BTRFS_SNAPSHOT_H */ - -/* - * Local Variables: - * mode:C++ - * End: - */ diff --git a/lib/sbuild/chroot-facet-session-clonable.cc b/lib/sbuild/chroot-facet-session-clonable.cc index c8e771a4..3e467357 100644 --- a/lib/sbuild/chroot-facet-session-clonable.cc +++ b/lib/sbuild/chroot-facet-session-clonable.cc @@ -34,7 +34,7 @@ #include <sbuild/chroot/loopback.h> #endif // SBUILD_FEATURE_LOOPBACK #ifdef SBUILD_FEATURE_BTRFSSNAP -#include "chroot-btrfs-snapshot.h" +#include <sbuild/chroot/btrfs-snapshot.h> #endif // SBUILD_FEATURE_BTRFSSNAP #ifdef SBUILD_FEATURE_UNION #include "chroot-facet-union.h" @@ -185,7 +185,7 @@ chroot_facet_session_clonable::clone_session_setup (chroot::chroot const& parent #ifdef SBUILD_FEATURE_BTRFSSNAP /* Btrfs snapshots need the snapshot name specifying. */ - std::shared_ptr<chroot_btrfs_snapshot> btrfs_snapshot(std::dynamic_pointer_cast<chroot_btrfs_snapshot>(clone)); + std::shared_ptr<chroot::btrfs_snapshot> btrfs_snapshot(std::dynamic_pointer_cast<chroot::btrfs_snapshot>(clone)); if (btrfs_snapshot && !btrfs_snapshot->get_snapshot_directory().empty()) { std::string snapname(btrfs_snapshot->get_snapshot_directory()); diff --git a/lib/sbuild/chroot/btrfs-snapshot.cc b/lib/sbuild/chroot/btrfs-snapshot.cc new file mode 100644 index 00000000..97d0b208 --- /dev/null +++ b/lib/sbuild/chroot/btrfs-snapshot.cc @@ -0,0 +1,276 @@ +/* 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 <config.h> + +#include <chroot/btrfs-snapshot.h> +#include <sbuild/chroot/directory.h> +#include "chroot-facet-session.h" +#include "chroot-facet-session-clonable.h" +#include "chroot-facet-source-clonable.h" +#include "format-detail.h" +#include "lock.h" + +#include <cassert> +#include <cerrno> + +#include <boost/format.hpp> + +using std::endl; +using boost::format; +using namespace sbuild; + +namespace sbuild +{ + namespace chroot + { + + btrfs_snapshot::btrfs_snapshot (): + chroot(), + source_subvolume(), + snapshot_directory(), + snapshot_name() + { + add_facet(chroot_facet_source_clonable::create()); + } + + btrfs_snapshot::btrfs_snapshot (const btrfs_snapshot& rhs): + chroot(rhs), + source_subvolume(rhs.source_subvolume), + snapshot_directory(rhs.snapshot_directory), + snapshot_name(rhs.snapshot_name) + { + } + + btrfs_snapshot::~btrfs_snapshot () + { + } + + chroot::chroot::ptr + btrfs_snapshot::clone () const + { + 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 + { + chroot_facet_session_clonable::const_ptr psess + (get_facet<chroot_facet_session_clonable>()); + assert(psess); + + ptr session(new btrfs_snapshot(*this)); + psess->clone_session_setup(*this, session, session_id, alias, user, root); + + return session; + } + + chroot::chroot::ptr + btrfs_snapshot::clone_source () const + { + ptr clone(new directory(*this)); + + chroot_facet_source_clonable::const_ptr psrc + (get_facet<chroot_facet_source_clonable>()); + assert(psrc); + + psrc->clone_source_setup(*this, clone); + + return clone; + } + + std::string const& + btrfs_snapshot::get_source_subvolume () const + { + return this->source_subvolume; + } + + void + btrfs_snapshot::set_source_subvolume (std::string const& source_subvolume) + { + if (!is_absname(source_subvolume)) + throw error(source_subvolume, DIRECTORY_ABS); + + this->source_subvolume = source_subvolume; + } + + std::string const& + btrfs_snapshot::get_snapshot_directory () const + { + return this->snapshot_directory; + } + + void + btrfs_snapshot::set_snapshot_directory (std::string const& snapshot_directory) + { + if (!is_absname(snapshot_directory)) + throw error(source_subvolume, DIRECTORY_ABS); + + this->snapshot_directory = snapshot_directory; + } + + std::string const& + btrfs_snapshot::get_snapshot_name () const + { + return this->snapshot_name; + } + + void + btrfs_snapshot::set_snapshot_name (std::string const& snapshot_name) + { + if (!is_absname(snapshot_name)) + throw error(source_subvolume, DIRECTORY_ABS); + + this->snapshot_name = snapshot_name; + } + + std::string const& + btrfs_snapshot::get_chroot_type () const + { + static const std::string type("btrfs-snapshot"); + + return type; + } + + std::string + btrfs_snapshot::get_path () const + { + return get_mount_location(); + } + + void + btrfs_snapshot::setup_env (chroot const& chroot, + environment& env) const + { + chroot::setup_env(chroot, env); + + env.add("CHROOT_BTRFS_SOURCE_SUBVOLUME", get_source_subvolume()); + env.add("CHROOT_BTRFS_SNAPSHOT_DIRECTORY", get_snapshot_directory()); + env.add("CHROOT_BTRFS_SNAPSHOT_NAME", get_snapshot_name()); + } + + void + btrfs_snapshot::setup_lock (chroot::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); + } + } + + chroot::chroot::session_flags + btrfs_snapshot::get_session_flags (chroot const& chroot) const + { + session_flags flags = SESSION_NOFLAGS; + + if (get_facet<chroot_facet_session>()) + flags = flags | SESSION_PURGE; + + return flags; + } + + void + btrfs_snapshot::get_details (chroot const& chroot, + format_detail& detail) const + { + chroot::get_details(chroot, detail); + + if (!this->get_source_subvolume().empty()) + detail.add(_("Btrfs Source Subvolume"), get_source_subvolume()); + if (!this->get_snapshot_directory().empty()) + detail.add(_("Btrfs Snapshot Directory"), get_snapshot_directory()); + if (!this->get_snapshot_name().empty()) + detail.add(_("Btrfs Snapshot Name"), get_snapshot_name()); + } + + void + btrfs_snapshot::get_used_keys (string_list& used_keys) const + { + chroot::get_used_keys(used_keys); + + used_keys.push_back("btrfs-source-subvolume"); + used_keys.push_back("btrfs-snapshot-directory"); + used_keys.push_back("btrfs-snapshot-name"); + } + + void + btrfs_snapshot::get_keyfile (chroot const& chroot, + keyfile& keyfile) const + { + chroot::get_keyfile(chroot, keyfile); + + bool session = static_cast<bool>(get_facet<chroot_facet_session>()); + + if (!session) + keyfile::set_object_value(*this, + &btrfs_snapshot::get_source_subvolume, + keyfile, get_name(), + "btrfs-source-subvolume"); + + if (!session) + keyfile::set_object_value(*this, + &btrfs_snapshot::get_snapshot_directory, + keyfile, get_name(), + "btrfs-snapshot-directory"); + + if (session) + keyfile::set_object_value(*this, + &btrfs_snapshot::get_snapshot_name, + keyfile, get_name(), + "btrfs-snapshot-name"); + } + + void + btrfs_snapshot::set_keyfile (chroot& chroot, + keyfile const& keyfile) + { + chroot::set_keyfile(chroot, keyfile); + + bool session = static_cast<bool>(get_facet<chroot_facet_session>()); + + keyfile::get_object_value(*this, &btrfs_snapshot::set_source_subvolume, + keyfile, get_name(), "btrfs-source-subvolume", + session ? + keyfile::PRIORITY_DISALLOWED : + keyfile::PRIORITY_REQUIRED + ); // Only needed for creating snapshot, not using snapshot + + keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_directory, + keyfile, get_name(), "btrfs-snapshot-directory", + session ? + keyfile::PRIORITY_DISALLOWED : + keyfile::PRIORITY_REQUIRED + ); // Only needed for creating snapshot, not using snapshot + + keyfile::get_object_value(*this, &btrfs_snapshot::set_snapshot_name, + keyfile, get_name(), "btrfs-snapshot-name", + session ? + keyfile::PRIORITY_REQUIRED : + keyfile::PRIORITY_DISALLOWED); + } + + } +} diff --git a/lib/sbuild/chroot/btrfs-snapshot.h b/lib/sbuild/chroot/btrfs-snapshot.h new file mode 100644 index 00000000..81b64387 --- /dev/null +++ b/lib/sbuild/chroot/btrfs-snapshot.h @@ -0,0 +1,164 @@ +/* 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_BTRFS_SNAPSHOT_H +#define SBUILD_CHROOT_BTRFS_SNAPSHOT_H + +#include <sbuild/chroot/chroot.h> + +namespace sbuild +{ + namespace chroot + { + /** + * A chroot stored on an BTRFS logical volume (LV). + * + * A snapshot LV will be created and mounted on demand. + */ + class btrfs_snapshot : public chroot + { + protected: + /// The constructor. + btrfs_snapshot (); + + /// The copy constructor. + btrfs_snapshot (const btrfs_snapshot& rhs); + + friend class chroot; + + public: + /// The destructor. + virtual ~btrfs_snapshot (); + + 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; + + virtual chroot::ptr + clone_source () const; + + /** + * Get the source subvolume path. This is used by "btrfs + * subvolume snapshot". + * + * @returns the source subvolume. + */ + std::string const& + get_source_subvolume () const; + + /** + * Set the source subvolume path. This is used by "btrfs + * subvolume snapshot". + * + * @param source_subvolume the source subvolume. + */ + void + set_source_subvolume (std::string const& source_subvolume); + + /** + * Get the snapshot directory. + * + * @returns the directory. + */ + std::string const& + get_snapshot_directory () const; + + /** + * Set the snapshot directory. + * + * @param snapshot_directory the snapshot directory. + */ + void + set_snapshot_directory (std::string const& snapshot_directory); + + /** + * Get the snapshot name. This is used by "btrfs subvolume + * snapshot", and is the full path to the snapshot. + * + * @returns the name. + */ + std::string const& + get_snapshot_name () const; + + /** + * Set the snapshot name. This is used by "btrfs subvolume + * snapshot", and is the full path to the snapshot. + * + * @param snapshot_name the snapshot name. + */ + void + set_snapshot_name (std::string const& snapshot_name); + + virtual std::string const& + get_chroot_type () const; + + virtual std::string + get_path () const; + + virtual void + setup_env (chroot const& chroot, + environment& env) 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); + + private: + /// Btrfs source subvolume + std::string source_subvolume; + /// Btrfs snapshot path + std::string snapshot_directory; + /// Btrfs snapshot name + std::string snapshot_name; + }; + + } +} + +#endif /* SBUILD_CHROOT_BTRFS_SNAPSHOT_H */ + +/* + * Local Variables: + * mode:C++ + * End: + */ diff --git a/lib/sbuild/chroot/chroot.cc b/lib/sbuild/chroot/chroot.cc index ad4c39ff..6450cdee 100644 --- a/lib/sbuild/chroot/chroot.cc +++ b/lib/sbuild/chroot/chroot.cc @@ -34,7 +34,7 @@ #include <sbuild/chroot/lvm-snapshot.h> #endif // SBUILD_FEATURE_LVMSNAP #ifdef SBUILD_FEATURE_BTRFSSNAP -#include "chroot-btrfs-snapshot.h" +#include <sbuild/chroot/btrfs-snapshot.h> #endif // SBUILD_FEATURE_BTRFSSNAP #include "chroot-facet.h" #include "chroot-facet-personality.h" @@ -187,7 +187,7 @@ namespace sbuild #endif // SBUILD_FEATURE_LVMSNAP #ifdef SBUILD_FEATURE_BTRFSSNAP else if (type == "btrfs-snapshot") - new_chroot = new chroot_btrfs_snapshot(); + new_chroot = new btrfs_snapshot(); #endif // SBUILD_FEATURE_BTRFSSNAP else throw error(type, CHROOT_TYPE); diff --git a/lib/sbuild/chroot/directory.cc b/lib/sbuild/chroot/directory.cc index 93978be9..87547d65 100644 --- a/lib/sbuild/chroot/directory.cc +++ b/lib/sbuild/chroot/directory.cc @@ -56,7 +56,7 @@ namespace sbuild } #ifdef SBUILD_FEATURE_BTRFSSNAP - directory::directory (const chroot_btrfs_snapshot& rhs): + directory::directory (const btrfs_snapshot& rhs): directory_base(rhs) { #ifdef SBUILD_FEATURE_UNION diff --git a/lib/sbuild/chroot/directory.h b/lib/sbuild/chroot/directory.h index 450a387b..1c414880 100644 --- a/lib/sbuild/chroot/directory.h +++ b/lib/sbuild/chroot/directory.h @@ -21,7 +21,9 @@ #include <sbuild/config.h> #include <sbuild/chroot/directory-base.h> -#include <sbuild/chroot-btrfs-snapshot.h> +#ifdef SBUILD_FEATURE_BTRFSSNAP +#include <sbuild/chroot/btrfs-snapshot.h> +#endif namespace sbuild { @@ -45,12 +47,12 @@ namespace sbuild #ifdef SBUILD_FEATURE_BTRFSSNAP /// The copy constructor. - directory (const chroot_btrfs_snapshot& rhs); + directory (const btrfs_snapshot& rhs); #endif friend class chroot; #ifdef SBUILD_FEATURE_BTRFSSNAP - friend class sbuild::chroot_btrfs_snapshot; + friend class btrfs_snapshot; #endif public: diff --git a/test/sbuild/chroot-btrfs-snapshot.cc b/test/sbuild/chroot-btrfs-snapshot.cc index 4e6291a6..8ec1347a 100644 --- a/test/sbuild/chroot-btrfs-snapshot.cc +++ b/test/sbuild/chroot-btrfs-snapshot.cc @@ -18,7 +18,7 @@ #include <config.h> -#include <sbuild/chroot-btrfs-snapshot.h> +#include <sbuild/chroot/btrfs-snapshot.h> #include <sbuild/i18n.h> #include <sbuild/keyfile-writer.h> #include <sbuild/util.h> @@ -34,11 +34,11 @@ using namespace CppUnit; using sbuild::_; -class chroot_btrfs_snapshot : public sbuild::chroot_btrfs_snapshot +class chroot_btrfs_snapshot : public sbuild::chroot::btrfs_snapshot { public: chroot_btrfs_snapshot(): - sbuild::chroot_btrfs_snapshot() + sbuild::chroot::btrfs_snapshot() {} virtual ~chroot_btrfs_snapshot() @@ -87,7 +87,7 @@ public: { test_chroot_base<chroot_btrfs_snapshot>::setup_chroot_props(chroot); - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); c->set_source_subvolume("/srv/chroot/sid"); c->set_snapshot_directory("/srv/chroot/snapshot"); @@ -96,7 +96,7 @@ public: void test_source_subvolume() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); CPPUNIT_ASSERT(c); c->set_source_subvolume("/srv/chroot/chroot"); CPPUNIT_ASSERT(c->get_source_subvolume() == "/srv/chroot/chroot"); @@ -105,7 +105,7 @@ public: void test_snapshot_directory() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); CPPUNIT_ASSERT(c); c->set_snapshot_directory("/srv/chroot/snapshot2"); CPPUNIT_ASSERT(c->get_snapshot_directory() == "/srv/chroot/snapshot2"); @@ -114,7 +114,7 @@ public: void test_snapshot_name() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); CPPUNIT_ASSERT(c); c->set_snapshot_directory("/srv/chroot/snapshot2/test-session-id"); CPPUNIT_ASSERT(c->get_snapshot_directory() == "/srv/chroot/snapshot2/test-session-id"); @@ -123,7 +123,7 @@ public: void test_source_subvolume_error() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); CPPUNIT_ASSERT(c); c->set_source_subvolume("chroot/invalid"); } @@ -131,7 +131,7 @@ public: void test_snapshot_directory_error() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); CPPUNIT_ASSERT(c); c->set_snapshot_directory("chroot/invalid"); } @@ -139,7 +139,7 @@ public: void test_snapshot_name_error() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); CPPUNIT_ASSERT(c); c->set_snapshot_name("invalid"); } @@ -172,7 +172,7 @@ public: void test_setup_env_session() { - std::shared_ptr<sbuild::chroot_btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot_btrfs_snapshot>(chroot); + std::shared_ptr<sbuild::chroot::btrfs_snapshot> c = std::dynamic_pointer_cast<sbuild::chroot::btrfs_snapshot>(chroot); sbuild::environment expected; setup_env_gen(expected); |