source: trunk/debathena/third/schroot/sbuild/sbuild-chroot-directory-base.cc @ 24167

Revision 24167, 3.4 KB checked in by broder, 15 years ago (diff)
Import schroot upstream into subversion.
Line 
1/* Copyright © 2005-2007  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-base.h"
22#include "sbuild-format-detail.h"
23#include "sbuild-lock.h"
24
25#include <cerrno>
26
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <sys/sysmacros.h>
30#include <unistd.h>
31
32using namespace sbuild;
33
34chroot_directory_base::chroot_directory_base ():
35  chroot()
36{
37}
38
39chroot_directory_base::~chroot_directory_base ()
40{
41}
42
43std::string const&
44chroot_directory_base::get_directory () const
45{
46  return this->directory;
47}
48
49void
50chroot_directory_base::set_directory (std::string const& directory)
51{
52  if (!is_absname(directory))
53    throw chroot::error(directory, DIRECTORY_ABS);
54
55  this->directory = directory;
56}
57
58void
59chroot_directory_base::setup_env (chroot const& chroot,
60                                  environment& env) const
61{
62  chroot::setup_env(chroot, env);
63
64  env.add("CHROOT_DIRECTORY", get_directory());
65}
66
67void
68chroot_directory_base::get_details (chroot const& chroot,
69                                    format_detail& detail) const
70{
71  chroot::get_details(chroot, detail);
72
73  detail.add(_("Directory"), get_directory());
74}
75
76void
77chroot_directory_base::get_keyfile (chroot const& chroot,
78                                    keyfile& keyfile) const
79{
80  chroot::get_keyfile(chroot, keyfile);
81
82  keyfile::set_object_value(*this, &chroot_directory_base::get_directory,
83                            keyfile, get_keyfile_name(), "directory");
84}
85
86void
87chroot_directory_base::set_keyfile (chroot&        chroot,
88                                    keyfile const& keyfile,
89                                    string_list&   used_keys)
90{
91  chroot::set_keyfile(chroot, keyfile, used_keys);
92
93  // "directory" should be required, but we also accept "location" as
94  // an alternative (but deprecated) variant.  Therefore, ensure by
95  // hand that one of them is defined, but not both.
96
97  bool directory_key = keyfile.has_key(get_keyfile_name(), "directory");
98  bool location_key = keyfile.has_key(get_keyfile_name(), "location");
99
100  keyfile::priority directory_priority = keyfile::PRIORITY_OPTIONAL;
101  keyfile::priority location_priority = keyfile::PRIORITY_DEPRECATED;
102
103  if (!directory_key && !location_key)
104    throw keyfile::error(get_keyfile_name(), keyfile::MISSING_KEY_NL, "directory");
105
106  // Using both keys is not allowed (which one is the correct one?),
107  // so force an exception to be thrown when reading the old location
108  // key.
109  if (directory_key && location_key)
110    location_priority = keyfile::PRIORITY_DISALLOWED;
111
112  keyfile::get_object_value(*this, &chroot_directory_base::set_directory,
113                            keyfile, get_keyfile_name(), "directory",
114                            directory_priority);
115  used_keys.push_back("directory");
116
117  keyfile::get_object_value(*this, &chroot_directory_base::set_directory,
118                            keyfile, get_keyfile_name(), "location",
119                            location_priority);
120  used_keys.push_back("location");
121}
Note: See TracBrowser for help on using the repository browser.