From: Mark Huang Date: Sun, 21 Aug 2005 22:24:39 +0000 (+0000) Subject: - sync to util-vserver-0.30.207 (yes, 207; this is the latest version of X-Git-Tag: after-util-vserver-0_30_208-revert~133 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=41bd1307812403947526e827ea3d167794e6be0f;p=util-vserver.git - sync to util-vserver-0.30.207 (yes, 207; this is the latest version of it before it got deleted) --- diff --git a/src/vserver.cc b/src/vserver.cc new file mode 100644 index 0000000..cddcf11 --- /dev/null +++ b/src/vserver.cc @@ -0,0 +1,75 @@ +// $Id: vserver.cc,v 1.1 2003/10/21 13:26:21 ensc Exp $ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// This program 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; version 2 of the License. +// +// This program 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. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "vserver.hh" +#include "pathconfig.h" + +#include +#include +#include +#include +#include + +static bool +dirExists(std::string const &path) +{ + struct stat st; + return (stat(path.c_str(), &st)!=-1 && + S_ISDIR(st.st_mode)); +} + +Vserver::Vserver(std::string const &str) : + conf_dir_(str), vdir_(str), name_(str) +{ + vdir_ += "/.vdir"; + + if (!dirExists(vdir_)) { + conf_dir_ = CONFDIR; + conf_dir_ += str; + } + + rpmdb_path_ = conf_dir_; + rpmdb_path_ += "/apps/pkgmgmt/rpmstate"; + + if (!dirExists(rpmdb_path_)) { + rpmdb_path_ = conf_dir_; + rpmdb_path_ += "/apps/pkgmgmt/base/rpm/state"; + } + + if (!dirExists(rpmdb_path_)) { + rpmdb_path_ = vdir_; + rpmdb_path_ += "/var/lib/rpm"; + } + + std::string tmp = conf_dir_; + tmp += ".name"; + + std::ifstream name_file(tmp.c_str()); + + if (name_file.good()) getline(name_file, name_); +} + +std::ostream & +operator << (std::ostream &lhs, Vserver const &rhs) +{ + return lhs << rhs.getName(); +} diff --git a/src/vserver.hh b/src/vserver.hh new file mode 100644 index 0000000..b0059dc --- /dev/null +++ b/src/vserver.hh @@ -0,0 +1,45 @@ +// $Id: vserver.hh,v 1.1 2003/10/21 13:26:21 ensc Exp $ --*- c++ -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// This program 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; version 2 of the License. +// +// This program 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 HH_UTIL_VSERVER_SRC_VSERVSER_HH +#define HH_UTIL_VSERVER_SRC_VSERVSER_HH + +#include +#include + +class Vserver +{ + public: + Vserver(std::string const &name); + + std::string const & getConfDir() const { return conf_dir_; } + std::string const & getVdir() const { return vdir_; } + std::string const & getRPMDbPath() const { return rpmdb_path_; } + std::string const & getName() const { return name_; } + + private: + std::string conf_dir_; + std::string vdir_; + std::string rpmdb_path_; + std::string name_; +}; + +std::ostream & operator << (std::ostream &lhs, Vserver const &rhs); + + +#endif // HH_UTIL_VSERVER_SRC_VSERVSER_HH diff --git a/src/vutil.p b/src/vutil.p index 32b5ce7..29a2c61 100644 --- a/src/vutil.p +++ b/src/vutil.p @@ -1,4 +1,4 @@ -// $Id: vutil.p,v 1.1 2003/09/29 22:01:57 ensc Exp $ --*- c++ -*-- +// $Id: vutil.p,v 1.3 2003/10/21 13:23:12 ensc Exp $ --*- c++ -*-- // Copyright (C) 2003 Enrico Scholz // based on vutil.p by Jacques Gelinas @@ -30,7 +30,7 @@ int vbuild_chown (const char *path, uid_t uid, gid_t gid); int vbuild_file_copy (const char *src, const char *dst, struct stat&st); -void vutil_loadallpkg (string&refserver, list&packages); +void vutil_loadallpkg (Vserver const &refserver, list&packages); int vutil_lstat (string path, struct stat&st); FILE *vutil_execdistcmd (const char *key, const string&vserver,