sbuild-chroot-directory.cc

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software; you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
00017  *
00018  *********************************************************************/
00019 
00020 #include <config.h>
00021 
00022 #include "sbuild-chroot-directory.h"
00023 #include "sbuild-format-detail.h"
00024 #include "sbuild-lock.h"
00025 
00026 #include <cerrno>
00027 
00028 #include <sys/types.h>
00029 #include <sys/stat.h>
00030 #include <sys/sysmacros.h>
00031 #include <unistd.h>
00032 
00033 using namespace sbuild;
00034 
00035 chroot_directory::chroot_directory ():
00036   chroot()
00037 {
00038 }
00039 
00040 chroot_directory::~chroot_directory ()
00041 {
00042 }
00043 
00044 sbuild::chroot::ptr
00045 chroot_directory::clone () const
00046 {
00047   return ptr(new chroot_directory(*this));
00048 }
00049 
00050 std::string const&
00051 chroot_directory::get_location () const
00052 {
00053   return chroot::get_location();
00054 }
00055 
00056 void
00057 chroot_directory::set_location (std::string const& location)
00058 {
00059   if (!is_absname(location))
00060     throw error(location, LOCATION_ABS);
00061 
00062   chroot::set_location(location);
00063 }
00064 
00065 std::string
00066 chroot_directory::get_path () const
00067 {
00068   // When running setup scripts, we are session-capable, so the path
00069   // is the bind-mounted location, rather than the original location.
00070   if (get_run_setup_scripts() == true)
00071     return get_mount_location();
00072   else
00073     return get_location();
00074 }
00075 
00076 std::string const&
00077 chroot_directory::get_chroot_type () const
00078 {
00079   static const std::string type("directory");
00080 
00081   return type;
00082 }
00083 
00084 void
00085 chroot_directory::setup_lock (chroot::setup_type type,
00086                               bool               lock,
00087                               int                status)
00088 {
00089   /* By default, directory chroots do no locking. */
00090   /* Create or unlink session information. */
00091   if (get_run_setup_scripts() == true)
00092     {
00093       if ((type == SETUP_START && lock == true) ||
00094           (type == SETUP_STOP && lock == false && status == 0))
00095         {
00096           bool start = (type == SETUP_START);
00097           setup_session_info(start);
00098         }
00099     }
00100 }
00101 
00102 sbuild::chroot::session_flags
00103 chroot_directory::get_session_flags () const
00104 {
00105   if (get_run_setup_scripts() == true)
00106     return SESSION_CREATE;
00107   else
00108     return static_cast<session_flags>(0);
00109 }
00110 
00111 void
00112 chroot_directory::get_details (format_detail& detail) const
00113 {
00114   chroot::get_details(detail);
00115 }
00116 
00117 void
00118 chroot_directory::get_keyfile (keyfile& keyfile) const
00119 {
00120   chroot::get_keyfile(keyfile);
00121 
00122   keyfile::set_object_value(*this, &chroot_directory::get_location,
00123                             keyfile, get_name(), "location");
00124 }
00125 
00126 void
00127 chroot_directory::set_keyfile (keyfile const& keyfile)
00128 {
00129   chroot::set_keyfile(keyfile);
00130 
00131   keyfile::get_object_value(*this, &chroot_directory::set_location,
00132                             keyfile, get_name(), "location",
00133                             keyfile::PRIORITY_REQUIRED);
00134 }

Generated on Sat Jan 27 16:11:03 2007 for schroot by  doxygen 1.5.1