[24167] | 1 | /* Copyright © 2005-2008 Roger Leigh <rleigh@debian.org> |
---|
| 2 | * |
---|
| 3 | * schroot is free software: you can redistribute it and/or modify it |
---|
| 4 | * under the terms of the GNU General Public License as published by |
---|
| 5 | * the Free Software Foundation, either version 3 of the License, or |
---|
| 6 | * (at your option) any later version. |
---|
| 7 | * |
---|
| 8 | * schroot is distributed in the hope that it will be useful, but |
---|
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
| 11 | * General Public License for more details. |
---|
| 12 | * |
---|
| 13 | * You should have received a copy of the GNU General Public License |
---|
| 14 | * along with this program. If not, see |
---|
| 15 | * <http://www.gnu.org/licenses/>. |
---|
| 16 | * |
---|
| 17 | *********************************************************************/ |
---|
| 18 | |
---|
| 19 | #include <config.h> |
---|
| 20 | |
---|
| 21 | #include "sbuild-chroot-block-device.h" |
---|
| 22 | #include "sbuild-chroot-lvm-snapshot.h" |
---|
| 23 | #include "sbuild-chroot-facet-mountable.h" |
---|
| 24 | #ifdef SBUILD_FEATURE_UNION |
---|
| 25 | #include "sbuild-chroot-facet-union.h" |
---|
| 26 | #endif // SBUILD_FEATURE_UNION |
---|
| 27 | #include "sbuild-format-detail.h" |
---|
| 28 | #include "sbuild-lock.h" |
---|
| 29 | #include "sbuild-util.h" |
---|
| 30 | |
---|
| 31 | #include <cerrno> |
---|
| 32 | #include <cstring> |
---|
| 33 | |
---|
| 34 | #include <boost/format.hpp> |
---|
| 35 | |
---|
| 36 | using boost::format; |
---|
| 37 | using namespace sbuild; |
---|
| 38 | |
---|
| 39 | chroot_block_device_base::chroot_block_device_base (): |
---|
| 40 | chroot(), |
---|
| 41 | device() |
---|
| 42 | { |
---|
| 43 | add_facet(sbuild::chroot_facet_mountable::create()); |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | chroot_block_device_base::chroot_block_device_base |
---|
| 47 | (const chroot_block_device_base& rhs): |
---|
| 48 | chroot(rhs), |
---|
| 49 | device() |
---|
| 50 | { |
---|
| 51 | /// @todo Required to set mount_device. Remove once no longer |
---|
| 52 | /// needed. |
---|
| 53 | if (!rhs.device.empty()) |
---|
| 54 | set_device(rhs.device); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | chroot_block_device_base::~chroot_block_device_base () |
---|
| 58 | { |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | std::string const& |
---|
| 62 | chroot_block_device_base::get_device () const |
---|
| 63 | { |
---|
| 64 | return this->device; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | void |
---|
| 68 | chroot_block_device_base::set_device (std::string const& device) |
---|
| 69 | { |
---|
| 70 | if (!is_absname(device)) |
---|
| 71 | throw error(device, DEVICE_ABS); |
---|
| 72 | |
---|
| 73 | this->device = device; |
---|
| 74 | |
---|
| 75 | /// @todo: This may not be appropriate for derived classes such as |
---|
| 76 | /// lvm_snapshot, since re-setting the device could overwrite the |
---|
| 77 | /// mount device. |
---|
| 78 | chroot_facet_mountable::ptr pmnt |
---|
| 79 | (get_facet<chroot_facet_mountable>()); |
---|
[24314] | 80 | #ifdef SBUILD_FEATURE_LVMSNAP |
---|
[24167] | 81 | if (!dynamic_cast<chroot_lvm_snapshot *>(this)) |
---|
[24314] | 82 | #endif |
---|
[24167] | 83 | pmnt->set_mount_device(this->device); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | std::string |
---|
| 87 | chroot_block_device_base::get_path () const |
---|
| 88 | { |
---|
| 89 | chroot_facet_mountable::const_ptr pmnt |
---|
| 90 | (get_facet<chroot_facet_mountable>()); |
---|
| 91 | |
---|
| 92 | std::string path(get_mount_location()); |
---|
| 93 | |
---|
| 94 | if (pmnt) |
---|
| 95 | path += pmnt->get_location(); |
---|
| 96 | |
---|
| 97 | return path; |
---|
| 98 | } |
---|
| 99 | |
---|
| 100 | std::string const& |
---|
| 101 | chroot_block_device_base::get_chroot_type () const |
---|
| 102 | { |
---|
| 103 | static const std::string type("block-device"); |
---|
| 104 | |
---|
| 105 | return type; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | void |
---|
| 109 | chroot_block_device_base::setup_env (chroot const& chroot, |
---|
| 110 | environment& env) const |
---|
| 111 | { |
---|
| 112 | chroot::setup_env(chroot, env); |
---|
| 113 | |
---|
| 114 | env.add("CHROOT_DEVICE", get_device()); |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | sbuild::chroot::session_flags |
---|
| 118 | chroot_block_device_base::get_session_flags (chroot const& chroot) const |
---|
| 119 | { |
---|
| 120 | return chroot::SESSION_NOFLAGS; |
---|
| 121 | } |
---|
| 122 | |
---|
| 123 | void |
---|
| 124 | chroot_block_device_base::get_details (chroot const& chroot, |
---|
| 125 | format_detail& detail) const |
---|
| 126 | { |
---|
| 127 | this->chroot::get_details(chroot, detail); |
---|
| 128 | |
---|
| 129 | if (!this->device.empty()) |
---|
| 130 | detail.add(_("Device"), get_device()); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | void |
---|
| 134 | chroot_block_device_base::get_keyfile (chroot const& chroot, |
---|
| 135 | keyfile& keyfile) const |
---|
| 136 | { |
---|
| 137 | chroot::get_keyfile(chroot, keyfile); |
---|
| 138 | |
---|
| 139 | keyfile::set_object_value(*this, &chroot_block_device_base::get_device, |
---|
| 140 | keyfile, get_keyfile_name(), "device"); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | void |
---|
| 144 | chroot_block_device_base::set_keyfile (chroot& chroot, |
---|
| 145 | keyfile const& keyfile, |
---|
| 146 | string_list& used_keys) |
---|
| 147 | { |
---|
| 148 | chroot::set_keyfile(chroot, keyfile, used_keys); |
---|
| 149 | |
---|
| 150 | keyfile::get_object_value(*this, &chroot_block_device_base::set_device, |
---|
| 151 | keyfile, get_keyfile_name(), "device", |
---|
| 152 | keyfile::PRIORITY_REQUIRED); |
---|
| 153 | used_keys.push_back("device"); |
---|
| 154 | } |
---|