X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fvserver.cc;fp=src%2Fvserver.cc;h=cddcf11aeac43950b1c0ef3fa3cd6b2a3559b849;hb=780710c3d80b8776944dd1fc65a0fda64f399db0;hp=0000000000000000000000000000000000000000;hpb=8cf13bb177d92c93eb73dc8939777150536c2d00;p=util-vserver.git 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(); +}