source: trunk/debathena/third/schroot/sbuild/sbuild-chroot-facet-mountable.cc @ 24167

Revision 24167, 4.4 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
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
28using boost::format;
29using std::endl;
30using namespace sbuild;
31
32chroot_facet_mountable::chroot_facet_mountable ():
33  chroot_facet(),
34  mount_device(),
35  mount_options(),
36  location()
37{
38}
39
40chroot_facet_mountable::~chroot_facet_mountable ()
41{
42}
43
44chroot_facet_mountable::ptr
45chroot_facet_mountable::create ()
46{
47  return ptr(new chroot_facet_mountable());
48}
49
50chroot_facet::ptr
51chroot_facet_mountable::clone () const
52{
53  return ptr(new chroot_facet_mountable(*this));
54}
55
56std::string const&
57chroot_facet_mountable::get_name () const
58{
59  static const std::string name("mountable");
60
61  return name;
62}
63
64std::string const&
65chroot_facet_mountable::get_mount_device () const
66{
67  return this->mount_device;
68}
69
70void
71chroot_facet_mountable::set_mount_device (std::string const& mount_device)
72{
73  this->mount_device = mount_device;
74}
75
76std::string const&
77chroot_facet_mountable::get_mount_options () const
78{
79  return this->mount_options;
80}
81
82void
83chroot_facet_mountable::set_mount_options (std::string const& mount_options)
84{
85  this->mount_options = mount_options;
86}
87
88std::string const&
89chroot_facet_mountable::get_location () const
90{
91  return this->location;
92}
93
94void
95chroot_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
103void
104chroot_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
112chroot::session_flags
113chroot_facet_mountable::get_session_flags (chroot const& chroot) const
114{
115  return chroot::SESSION_NOFLAGS;
116}
117
118void
119chroot_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
130void
131chroot_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
148void
149chroot_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}
Note: See TracBrowser for help on using the repository browser.