1 | /* Copyright © 2005-2009 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.h" |
---|
22 | #include "sbuild-chroot-facet-mountable.h" |
---|
23 | |
---|
24 | #include <cassert> |
---|
25 | |
---|
26 | #include <boost/format.hpp> |
---|
27 | |
---|
28 | using boost::format; |
---|
29 | using std::endl; |
---|
30 | using namespace sbuild; |
---|
31 | |
---|
32 | chroot_facet_mountable::chroot_facet_mountable (): |
---|
33 | chroot_facet(), |
---|
34 | mount_device(), |
---|
35 | mount_options(), |
---|
36 | location() |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | chroot_facet_mountable::~chroot_facet_mountable () |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | chroot_facet_mountable::ptr |
---|
45 | chroot_facet_mountable::create () |
---|
46 | { |
---|
47 | return ptr(new chroot_facet_mountable()); |
---|
48 | } |
---|
49 | |
---|
50 | chroot_facet::ptr |
---|
51 | chroot_facet_mountable::clone () const |
---|
52 | { |
---|
53 | return ptr(new chroot_facet_mountable(*this)); |
---|
54 | } |
---|
55 | |
---|
56 | std::string const& |
---|
57 | chroot_facet_mountable::get_name () const |
---|
58 | { |
---|
59 | static const std::string name("mountable"); |
---|
60 | |
---|
61 | return name; |
---|
62 | } |
---|
63 | |
---|
64 | std::string const& |
---|
65 | chroot_facet_mountable::get_mount_device () const |
---|
66 | { |
---|
67 | return this->mount_device; |
---|
68 | } |
---|
69 | |
---|
70 | void |
---|
71 | chroot_facet_mountable::set_mount_device (std::string const& mount_device) |
---|
72 | { |
---|
73 | this->mount_device = mount_device; |
---|
74 | } |
---|
75 | |
---|
76 | std::string const& |
---|
77 | chroot_facet_mountable::get_mount_options () const |
---|
78 | { |
---|
79 | return this->mount_options; |
---|
80 | } |
---|
81 | |
---|
82 | void |
---|
83 | chroot_facet_mountable::set_mount_options (std::string const& mount_options) |
---|
84 | { |
---|
85 | this->mount_options = mount_options; |
---|
86 | } |
---|
87 | |
---|
88 | std::string const& |
---|
89 | chroot_facet_mountable::get_location () const |
---|
90 | { |
---|
91 | return this->location; |
---|
92 | } |
---|
93 | |
---|
94 | void |
---|
95 | chroot_facet_mountable::set_location (std::string const& location) |
---|
96 | { |
---|
97 | if (!location.empty() && !is_absname(location)) |
---|
98 | throw chroot::error(location, chroot::LOCATION_ABS); |
---|
99 | |
---|
100 | this->location = location; |
---|
101 | } |
---|
102 | |
---|
103 | void |
---|
104 | chroot_facet_mountable::setup_env (chroot const& chroot, |
---|
105 | environment& env) const |
---|
106 | { |
---|
107 | env.add("CHROOT_MOUNT_DEVICE", get_mount_device()); |
---|
108 | env.add("CHROOT_MOUNT_OPTIONS", get_mount_options()); |
---|
109 | env.add("CHROOT_LOCATION", get_location()); |
---|
110 | } |
---|
111 | |
---|
112 | chroot::session_flags |
---|
113 | chroot_facet_mountable::get_session_flags (chroot const& chroot) const |
---|
114 | { |
---|
115 | return chroot::SESSION_NOFLAGS; |
---|
116 | } |
---|
117 | |
---|
118 | void |
---|
119 | chroot_facet_mountable::get_details (chroot const& chroot, |
---|
120 | format_detail& detail) const |
---|
121 | { |
---|
122 | if (!get_mount_device().empty()) |
---|
123 | detail.add(_("Mount Device"), get_mount_device()); |
---|
124 | if (!get_mount_options().empty()) |
---|
125 | detail.add(_("Mount Options"), get_mount_options()); |
---|
126 | if (!get_location().empty()) |
---|
127 | detail.add(_("Location"), get_location()); |
---|
128 | } |
---|
129 | |
---|
130 | void |
---|
131 | chroot_facet_mountable::get_keyfile (chroot const& chroot, |
---|
132 | keyfile& keyfile) const |
---|
133 | { |
---|
134 | if (chroot.get_active()) |
---|
135 | keyfile::set_object_value(*this, &chroot_facet_mountable::get_mount_device, |
---|
136 | keyfile, chroot.get_keyfile_name(), |
---|
137 | "mount-device"); |
---|
138 | |
---|
139 | keyfile::set_object_value(*this, &chroot_facet_mountable::get_mount_options, |
---|
140 | keyfile, chroot.get_keyfile_name(), |
---|
141 | "mount-options"); |
---|
142 | |
---|
143 | keyfile::set_object_value(*this, &chroot_facet_mountable::get_location, |
---|
144 | keyfile, chroot.get_keyfile_name(), |
---|
145 | "location"); |
---|
146 | } |
---|
147 | |
---|
148 | void |
---|
149 | chroot_facet_mountable::set_keyfile (chroot& chroot, |
---|
150 | keyfile const& keyfile, |
---|
151 | string_list& used_keys) |
---|
152 | { |
---|
153 | keyfile::get_object_value(*this, &chroot_facet_mountable::set_mount_device, |
---|
154 | keyfile, chroot.get_keyfile_name(), |
---|
155 | "mount-device", |
---|
156 | chroot.get_active() ? |
---|
157 | keyfile::PRIORITY_REQUIRED : |
---|
158 | keyfile::PRIORITY_DISALLOWED); |
---|
159 | used_keys.push_back("mount-device"); |
---|
160 | |
---|
161 | keyfile::get_object_value(*this, &chroot_facet_mountable::set_mount_options, |
---|
162 | keyfile, chroot.get_keyfile_name(), |
---|
163 | "mount-options", |
---|
164 | keyfile::PRIORITY_OPTIONAL); |
---|
165 | used_keys.push_back("mount-options"); |
---|
166 | |
---|
167 | keyfile::get_object_value(*this, &chroot_facet_mountable::set_location, |
---|
168 | keyfile, chroot.get_keyfile_name(), |
---|
169 | "location", |
---|
170 | keyfile::PRIORITY_OPTIONAL); |
---|
171 | used_keys.push_back("location"); |
---|
172 | } |
---|