diff --git a/src/installtransaction.cpp b/src/installtransaction.cpp index 4cdd756..3bcec26 100644 --- a/src/installtransaction.cpp +++ b/src/installtransaction.cpp @@ -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& InstallTransaction::ignoredPackages() const @@ -652,7 +651,7 @@ const list& InstallTransaction::ignoredPackages() const return m_ignoredPackages; } -string InstallTransaction::pkgDest() const +string InstallTransaction::getPkgmkPackageDir() { - return m_pkgDest; + return getPkgmkSetting("PKGMK_PACKAGE_DIR"); } diff --git a/src/installtransaction.h b/src/installtransaction.h index 92cf6ba..248df8e 100644 --- a/src/installtransaction.h +++ b/src/installtransaction.h @@ -98,7 +98,7 @@ public: const list< pair >& missing() const; const list< pair >& 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 m_depNameList; vector m_depList; - // field for error messages - mutable string m_pkgDest; - // packages requested to be installed not found in the ports tree list< pair > m_missingPackages; diff --git a/src/prtget.cpp b/src/prtget.cpp index 9efd947..8dc94d9 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -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;