diff options
author | Roger Leigh <rleigh@debian.org> | 2006-06-23 10:31:34 +0000 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2006-06-23 10:31:34 +0000 |
commit | c9927df9800f869f94949cb7da1cb39cc7662a04 (patch) | |
tree | ebe601b64eb440ae4f1b639095b3c7709e4efc36 | |
parent | bf1828cd734db6806dd4a4e640e6fcd5581de9b3 (diff) | |
download | schroot-c9927df9800f869f94949cb7da1cb39cc7662a04.tar.gz |
* schroot/schroot.cc (main): When running dchroot-dsa, use
dchroot_dsa::chroot_config instead or dchroot::chroot_config.
* schroot/dchroot-chroot-config.(cc|h): New class. Remove
dchroot-dsa specific parts.
* schroot/dchroot-dsa-chroot-config.(cc|h): New class. Split
dchroot-dsa specific parts from dchroot::chroot_config.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | schroot/Makefile.am | 4 | ||||
-rw-r--r-- | schroot/dchroot-chroot-config.cc | 46 | ||||
-rw-r--r-- | schroot/dchroot-dsa-chroot-config.cc | 125 | ||||
-rw-r--r-- | schroot/dchroot-dsa-chroot-config.h | 74 | ||||
-rw-r--r-- | schroot/schroot.cc | 12 |
6 files changed, 233 insertions, 39 deletions
@@ -1,5 +1,16 @@ 2006-06-23 Roger Leigh <rleigh@debian.org> + * schroot/schroot.cc (main): When running dchroot-dsa, use + dchroot_dsa::chroot_config instead or dchroot::chroot_config. + + * schroot/dchroot-chroot-config.(cc|h): New class. Remove + dchroot-dsa specific parts. + + * schroot/dchroot-dsa-chroot-config.(cc|h): New class. Split + dchroot-dsa specific parts from dchroot::chroot_config. + +2006-06-23 Roger Leigh <rleigh@debian.org> + * schroot/Makefile.am: Build with new headers. * schroot/dchroot-session.h: Update API documentation. diff --git a/schroot/Makefile.am b/schroot/Makefile.am index f06b91b2..48509922 100644 --- a/schroot/Makefile.am +++ b/schroot/Makefile.am @@ -140,8 +140,8 @@ dchroot_CXXFLAGS = -DSBUILD_DCHROOT_COMPAT dchroot_LDADD = libsbuild.la dchroot_dsa_SOURCES = \ - dchroot-chroot-config.h \ - dchroot-chroot-config.cc \ + dchroot-dsa-chroot-config.h \ + dchroot-dsa-chroot-config.cc \ dchroot-session-base.h \ dchroot-session-base.cc \ dchroot-dsa-session.h \ diff --git a/schroot/dchroot-chroot-config.cc b/schroot/dchroot-chroot-config.cc index cd98de5f..e532a8ff 100644 --- a/schroot/dchroot-chroot-config.cc +++ b/schroot/dchroot-chroot-config.cc @@ -62,9 +62,8 @@ chroot_config::parse_data (std::istream& stream, std::string line; std::string chroot_name; std::string chroot_location; -#ifndef SBUILD_DCHROOT_DSA_COMPAT bool default_set = false; -#endif + while (std::getline(stream, line)) { linecount++; @@ -79,13 +78,7 @@ chroot_config::parse_data (std::istream& stream, } else // Item { - static const char *whitespace = -#ifndef SBUILD_DCHROOT_DSA_COMPAT - " \t" -#else - " \t:;," -#endif - ; + static const char *whitespace = " \t"; // Get chroot name std::string::size_type cstart = line.find_first_not_of(whitespace); @@ -96,7 +89,6 @@ chroot_config::parse_data (std::istream& stream, cend); std::string::size_type lend = line.find_first_of(whitespace, lstart); -#ifndef SBUILD_DCHROOT_DSA_COMPAT // Get chroot personality std::string::size_type pstart = line.find_first_not_of(whitespace, lend); @@ -105,8 +97,6 @@ chroot_config::parse_data (std::istream& stream, // Check for trailing non-whitespace. std::string::size_type tstart = line.find_first_not_of(whitespace, pend); -#endif - if (cstart == std::string::npos || cend == std::string::npos || lstart == std::string::npos) @@ -114,51 +104,38 @@ chroot_config::parse_data (std::istream& stream, throw parse_error(linecount, parse_error::INVALID_LINE, line); } -#ifndef SBUILD_DCHROOT_DSA_COMPAT if (tstart != std::string::npos) { throw parse_error(linecount, parse_error::INVALID_LINE, line); } -#endif std::string chroot_name = line.substr(cstart, cend - cstart); std::string location = line.substr(lstart, lend - lstart); -#ifndef SBUILD_DCHROOT_DSA_COMPAT std::string personality; if (pstart != std::string::npos) personality = line.substr(pstart, pend - pstart); -#else /* DSA dchroot parses valid users. */ - sbuild::string_list users; - if (lend != std::string::npos) - users = sbuild::split_string(line.substr(lend), whitespace); -#endif /* Create chroot object. */ sbuild::chroot::ptr chroot = sbuild::chroot::create("plain"); chroot->set_active(active); chroot->set_name(chroot_name); - chroot->set_description(chroot_name + -#ifndef SBUILD_DCHROOT_DSA_COMPAT - " chroot (dchroot compatibility)" -#else - " chroot (dchroot-dsa compatibility)" -#endif - ); - -#ifndef SBUILD_DCHROOT_DSA_COMPAT + + format fmt(_("%1% chroot (dchroot compatibility)")); + fmt % chroot_name; + chroot->set_description(fmt.str()); + if (pstart != std::string::npos) chroot->set_persona(sbuild::personality(personality)); -#else /* DSA dchroot set valid users in the user list. */ - chroot->set_users(users); -#endif sbuild::chroot_plain *plain = dynamic_cast<sbuild::chroot_plain *>(chroot.get()); plain->set_location(location); -#ifndef SBUILD_DCHROOT_DSA_COMPAT - // DSA dchroot doesn't support a default chroot. + if (chroot_name == "default") + default_set = true; + + // Set default chroot. if (!default_set) { sbuild::string_list aliases; @@ -166,7 +143,6 @@ chroot_config::parse_data (std::istream& stream, chroot->set_aliases(aliases); default_set = true; } -#endif add(chroot); } diff --git a/schroot/dchroot-dsa-chroot-config.cc b/schroot/dchroot-dsa-chroot-config.cc new file mode 100644 index 00000000..30d098a2 --- /dev/null +++ b/schroot/dchroot-dsa-chroot-config.cc @@ -0,0 +1,125 @@ +/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org> + * + * schroot is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + *********************************************************************/ + +#include <config.h> + +#include "sbuild.h" +#include "sbuild-parse-error.h" + +#include "dchroot-dsa-chroot-config.h" + +#include <iostream> + +#include <errno.h> +#include <stdlib.h> +#include <string.h> + +#include <boost/format.hpp> + +using std::endl; +using sbuild::parse_error; +using boost::format; +using namespace dchroot_dsa; + +chroot_config::chroot_config (): + sbuild::chroot_config() +{ +} + +chroot_config::chroot_config (std::string const& file, + bool active): + sbuild::chroot_config(file, active) +{ +} + +chroot_config::~chroot_config () +{ +} + +void +chroot_config::parse_data (std::istream& stream, + bool active) +{ + active = false; // dchroot does not support sessions. + + size_t linecount = 0; + std::string line; + std::string chroot_name; + std::string chroot_location; + + while (std::getline(stream, line)) + { + linecount++; + + if (line[0] == '#') + { + // Comment line; do nothing. + } + else if (line.length() == 0) + { + // Empty line; do nothing. + } + else // Item + { + static const char *whitespace = " \t:;,"; + + // Get chroot name + std::string::size_type cstart = line.find_first_not_of(whitespace); + std::string::size_type cend = line.find_first_of(whitespace, cstart); + + // Get chroot location + std::string::size_type lstart = line.find_first_not_of(whitespace, + cend); + std::string::size_type lend = line.find_first_of(whitespace, lstart); + + if (cstart == std::string::npos || + cend == std::string::npos || + lstart == std::string::npos) + { + throw parse_error(linecount, parse_error::INVALID_LINE, line); + } + + std::string chroot_name = line.substr(cstart, cend - cstart); + std::string location = line.substr(lstart, lend - lstart); + + /* DSA dchroot parses valid users. */ + sbuild::string_list users; + if (lend != std::string::npos) + users = sbuild::split_string(line.substr(lend), whitespace); + + /* Create chroot object. */ + sbuild::chroot::ptr chroot = sbuild::chroot::create("plain"); + chroot->set_active(active); + chroot->set_name(chroot_name); + + format fmt(_("%1% chroot (dchroot-dsa compatibility)")); + fmt % chroot_name; + chroot->set_description(fmt.str()); + + /* DSA dchroot set valid users in the user list. */ + chroot->set_users(users); + + sbuild::chroot_plain *plain = + dynamic_cast<sbuild::chroot_plain *>(chroot.get()); + plain->set_location(location); + + add(chroot); + } + } +} diff --git a/schroot/dchroot-dsa-chroot-config.h b/schroot/dchroot-dsa-chroot-config.h new file mode 100644 index 00000000..8848a62e --- /dev/null +++ b/schroot/dchroot-dsa-chroot-config.h @@ -0,0 +1,74 @@ +/* Copyright © 2005-2006 Roger Leigh <rleigh@debian.org> + * + * schroot is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * schroot is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + *********************************************************************/ + +#ifndef DCHROOT_DSA_CHROOT_CONFIG_H +#define DCHROOT_DSA_CHROOT_CONFIG_H + +#include <map> +#include <ostream> +#include <vector> +#include <string> + +#include "sbuild-chroot-config.h" + +namespace dchroot_dsa +{ + + /** + * Chroot configuration for dchroot-dsa compatibility. + * + * This class provides all the functionality of chroot_config, but + * parses the dchroot-dsa configuration file format, rather than the + * schroot format. + */ + class chroot_config : public sbuild::chroot_config + { + public: + /// The constructor. + chroot_config (); + + /** + * The constructor. + * + * @param file initialise using a configuration file or a whole + * directory containing configuration files. + * @param active true if the chroots in the configuration file are + * active sessions, otherwise false. + */ + chroot_config (std::string const& file, + bool active); + + /// The destructor. + virtual ~chroot_config (); + + private: + virtual void + parse_data (std::istream& stream, + bool active); + }; + +} + +#endif /* DCHROOT_DSA_CHROOT_CONFIG_H */ + +/* + * Local Variables: + * mode:C++ + * End: + */ diff --git a/schroot/schroot.cc b/schroot/schroot.cc index b808a351..3916ef70 100644 --- a/schroot/schroot.cc +++ b/schroot/schroot.cc @@ -39,7 +39,7 @@ #include "dchroot-session.h" #include "dchroot-options.h" #elif defined(SBUILD_DCHROOT_DSA_COMPAT) -#include "dchroot-chroot-config.h" +#include "dchroot-dsa-chroot-config.h" #include "dchroot-dsa-session.h" #include "dchroot-dsa-options.h" #else @@ -244,7 +244,7 @@ main (int argc, #endif sbuild::chroot_config::ptr config; -#ifdef SBUILD_DCHROOT_COMPAT +#if defined(SBUILD_DCHROOT_COMPAT) && !defined(SBUILD_DCHROOT_DSA_COMPAT) if (options->compat != options_base::COMPAT_SCHROOT && use_dchroot_conf) { config = sbuild::chroot_config::ptr(new dchroot::chroot_config); @@ -252,6 +252,14 @@ main (int argc, config->add(DCHROOT_CONF, false); } else +#elif defined(SBUILD_DCHROOT_DSA_COMPAT) + if (options->compat != options_base::COMPAT_SCHROOT && use_dchroot_conf) + { + config = sbuild::chroot_config::ptr(new dchroot_dsa::chroot_config); + if (options->load_chroots == true) + config->add(DCHROOT_CONF, false); + } + else #endif { config = sbuild::chroot_config::ptr(new sbuild::chroot_config); |