refactor getPkgDest(...) into getPkgmkSetting(...)

This commit is contained in:
Johannes Winkelmann 2010-05-18 21:13:25 +02:00
parent a423bd54f1
commit cf616df902
3 changed files with 20 additions and 23 deletions

View File

@ -309,7 +309,7 @@ InstallTransaction::installPackage( const Package* package,
result = PKGMK_FAILURE;
} else {
// -- update
string pkgdest = getPkgDest();
string pkgdest = getPkgmkPackageDir();
if ( pkgdest != "" ) {
// TODO: don't manipulate pkgdir
pkgdir = pkgdest;
@ -604,19 +604,18 @@ InstallTransaction::calcDependencies( )
/*
* getPkgDest assumes that you're in the build directory already
*/
string InstallTransaction::getPkgDest() const
string InstallTransaction::getPkgmkSetting(const string& setting)
{
string pkgdest = "";
pkgdest = getPkgDestFromFile("/etc/pkgmk.conf");
if (pkgdest.size() == 0) {
pkgdest = getPkgDestFromFile("/usr/bin/pkgmk");
string value = "";
value = getPkgmkSettingFromFile(setting, "/etc/pkgmk.conf");
if (value.size() == 0) {
value = getPkgmkSettingFromFile(setting, "/usr/bin/pkgmk");
}
m_pkgDest = pkgdest;
return pkgdest;
return value;
}
string InstallTransaction::getPkgDestFromFile(const string& fileName)
string InstallTransaction::getPkgmkSettingFromFile(const string& setting, const string& fileName)
{
FILE* fp = fopen(fileName.c_str(), "r");
if (!fp)
@ -627,24 +626,24 @@ string InstallTransaction::getPkgDestFromFile(const string& fileName)
char line[256];
while (fgets(line, 256, fp)) {
s = StringHelper::stripWhiteSpace(line);
if (StringHelper::startsWith(s, "PKGMK_PACKAGE_DIR=")) {
if (StringHelper::startsWith(s, setting + "=")) {
candidate = s;
}
}
fclose(fp);
string pkgdest = "";
string value = "";
if (candidate.length() > 0) {
string cmd = "eval " + candidate + " && echo $PKGMK_PACKAGE_DIR";
string cmd = "eval " + candidate + " && echo $" + setting;
FILE* p = popen(cmd.c_str(), "r");
if (p) {
fgets(line, 256, p);
pkgdest = StringHelper::stripWhiteSpace(line);
value = StringHelper::stripWhiteSpace(line);
fclose(p);
}
}
return pkgdest;
return value;
}
const list<string>& InstallTransaction::ignoredPackages() const
@ -652,7 +651,7 @@ const list<string>& InstallTransaction::ignoredPackages() const
return m_ignoredPackages;
}
string InstallTransaction::pkgDest() const
string InstallTransaction::getPkgmkPackageDir()
{
return m_pkgDest;
return getPkgmkSetting("PKGMK_PACKAGE_DIR");
}

View File

@ -98,7 +98,7 @@ public:
const list< pair<string,string> >& missing() const;
const list< pair<string, InstallInfo> >& installError() const;
string pkgDest() const;
static string getPkgmkPackageDir();
private:
bool calculateDependencies();
@ -109,8 +109,9 @@ private:
bool update,
InstallInfo& info ) const;
string getPkgDest() const;
static string getPkgDestFromFile(const string& fileName);
static string getPkgmkSetting(const string& setting);
static string getPkgmkSettingFromFile(const string& setting,
const string& fileName);
PkgDB* m_pkgDB;
DepResolver m_resolver;
@ -135,9 +136,6 @@ private:
list<string> m_depNameList;
vector<string> m_depList;
// field for error messages
mutable string m_pkgDest;
// packages requested to be installed not found in the ports tree
list< pair<string, string> > m_missingPackages;

View File

@ -689,7 +689,7 @@ void PrtGet::executeTransaction( InstallTransaction& transaction,
<< "Make sure it's installed properly" << endl;
} else if ( result == InstallTransaction::PKGDEST_ERROR ) {
cout << m_appName << ": error changing to PKGDEST directory "
<< transaction.pkgDest() << endl;
<< transaction.getPkgmkPackageDir() << endl;
failed = true;
} else if ( result == InstallTransaction::PKGADD_FAILURE ) {
cout << m_appName << ": error while pkgadding " << endl;