[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-directory.h" |
---|
| 22 | #include "sbuild-chroot-facet-session-clonable.h" |
---|
| 23 | #ifdef SBUILD_FEATURE_UNION |
---|
| 24 | #include "sbuild-chroot-facet-union.h" |
---|
| 25 | #endif // SBUILD_FEATURE_UNION |
---|
| 26 | #include "sbuild-format-detail.h" |
---|
| 27 | #include "sbuild-lock.h" |
---|
| 28 | |
---|
| 29 | #include <cassert> |
---|
| 30 | #include <cerrno> |
---|
| 31 | |
---|
| 32 | #include <sys/types.h> |
---|
| 33 | #include <sys/stat.h> |
---|
| 34 | #include <sys/sysmacros.h> |
---|
| 35 | #include <unistd.h> |
---|
| 36 | |
---|
| 37 | using namespace sbuild; |
---|
| 38 | |
---|
| 39 | chroot_directory::chroot_directory (): |
---|
| 40 | chroot_directory_base() |
---|
| 41 | { |
---|
| 42 | #ifdef SBUILD_FEATURE_UNION |
---|
| 43 | add_facet(sbuild::chroot_facet_union::create()); |
---|
| 44 | #endif // SBUILD_FEATURE_UNION |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | chroot_directory::chroot_directory (const chroot_directory& rhs): |
---|
| 48 | chroot_directory_base(rhs) |
---|
| 49 | { |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | chroot_directory::~chroot_directory () |
---|
| 53 | { |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | sbuild::chroot::ptr |
---|
| 57 | chroot_directory::clone () const |
---|
| 58 | { |
---|
| 59 | return ptr(new chroot_directory(*this)); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | sbuild::chroot::ptr |
---|
| 63 | chroot_directory::clone_session (std::string const& session_id, |
---|
| 64 | std::string const& user, |
---|
| 65 | bool root) const |
---|
| 66 | { |
---|
| 67 | chroot_facet_session_clonable::const_ptr psess |
---|
| 68 | (get_facet<chroot_facet_session_clonable>()); |
---|
| 69 | assert(psess); |
---|
| 70 | |
---|
| 71 | ptr session(new chroot_directory(*this)); |
---|
| 72 | psess->clone_session_setup(session, session_id, user, root); |
---|
| 73 | |
---|
| 74 | return session; |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | sbuild::chroot::ptr |
---|
| 78 | chroot_directory::clone_source () const |
---|
| 79 | { |
---|
| 80 | ptr clone; |
---|
| 81 | |
---|
| 82 | #ifdef SBUILD_FEATURE_UNION |
---|
| 83 | chroot_facet_union::const_ptr puni(get_facet<chroot_facet_union>()); |
---|
| 84 | assert(puni); |
---|
| 85 | |
---|
| 86 | if (puni->get_union_configured()) { |
---|
| 87 | clone = ptr(new chroot_directory(*this)); |
---|
| 88 | puni->clone_source_setup(clone); |
---|
| 89 | } |
---|
| 90 | #endif // SBUILD_FEATURE_UNION |
---|
| 91 | |
---|
| 92 | return clone; |
---|
| 93 | } |
---|
| 94 | |
---|
| 95 | std::string |
---|
| 96 | chroot_directory::get_path () const |
---|
| 97 | { |
---|
| 98 | return get_mount_location(); |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void |
---|
| 102 | chroot_directory::setup_env (chroot const& chroot, |
---|
| 103 | environment& env) const |
---|
| 104 | { |
---|
| 105 | chroot_directory_base::setup_env(chroot, env); |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | std::string const& |
---|
| 109 | chroot_directory::get_chroot_type () const |
---|
| 110 | { |
---|
| 111 | static const std::string type("directory"); |
---|
| 112 | |
---|
| 113 | return type; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | void |
---|
| 117 | chroot_directory::setup_lock (chroot::setup_type type, |
---|
| 118 | bool lock, |
---|
| 119 | int status) |
---|
| 120 | { |
---|
| 121 | /* Create or unlink session information. */ |
---|
| 122 | if ((type == SETUP_START && lock == true) || |
---|
| 123 | (type == SETUP_STOP && lock == false && status == 0)) |
---|
| 124 | { |
---|
| 125 | bool start = (type == SETUP_START); |
---|
| 126 | setup_session_info(start); |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | sbuild::chroot::session_flags |
---|
| 131 | chroot_directory::get_session_flags (chroot const& chroot) const |
---|
| 132 | { |
---|
| 133 | return chroot::SESSION_NOFLAGS; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | void |
---|
| 137 | chroot_directory::get_details (chroot const& chroot, |
---|
| 138 | format_detail& detail) const |
---|
| 139 | { |
---|
| 140 | chroot_directory_base::get_details(chroot, detail); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | void |
---|
| 144 | chroot_directory::get_keyfile (chroot const& chroot, |
---|
| 145 | keyfile& keyfile) const |
---|
| 146 | { |
---|
| 147 | chroot_directory_base::get_keyfile(chroot, keyfile); |
---|
| 148 | } |
---|
| 149 | |
---|
| 150 | void |
---|
| 151 | chroot_directory::set_keyfile (chroot& chroot, |
---|
| 152 | keyfile const& keyfile, |
---|
| 153 | string_list& used_keys) |
---|
| 154 | { |
---|
| 155 | chroot_directory_base::set_keyfile(chroot, keyfile, used_keys); |
---|
| 156 | } |
---|