refactor getPkgDest(...) into getPkgmkSetting(...)
This commit is contained in:
parent
a423bd54f1
commit
cf616df902
@ -309,7 +309,7 @@ InstallTransaction::installPackage( const Package* package,
|
|||||||
result = PKGMK_FAILURE;
|
result = PKGMK_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
// -- update
|
// -- update
|
||||||
string pkgdest = getPkgDest();
|
string pkgdest = getPkgmkPackageDir();
|
||||||
if ( pkgdest != "" ) {
|
if ( pkgdest != "" ) {
|
||||||
// TODO: don't manipulate pkgdir
|
// TODO: don't manipulate pkgdir
|
||||||
pkgdir = pkgdest;
|
pkgdir = pkgdest;
|
||||||
@ -604,19 +604,18 @@ InstallTransaction::calcDependencies( )
|
|||||||
/*
|
/*
|
||||||
* getPkgDest assumes that you're in the build directory already
|
* getPkgDest assumes that you're in the build directory already
|
||||||
*/
|
*/
|
||||||
string InstallTransaction::getPkgDest() const
|
string InstallTransaction::getPkgmkSetting(const string& setting)
|
||||||
{
|
{
|
||||||
string pkgdest = "";
|
string value = "";
|
||||||
pkgdest = getPkgDestFromFile("/etc/pkgmk.conf");
|
value = getPkgmkSettingFromFile(setting, "/etc/pkgmk.conf");
|
||||||
if (pkgdest.size() == 0) {
|
if (value.size() == 0) {
|
||||||
pkgdest = getPkgDestFromFile("/usr/bin/pkgmk");
|
value = getPkgmkSettingFromFile(setting, "/usr/bin/pkgmk");
|
||||||
}
|
}
|
||||||
|
|
||||||
m_pkgDest = pkgdest;
|
return value;
|
||||||
return pkgdest;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string InstallTransaction::getPkgDestFromFile(const string& fileName)
|
string InstallTransaction::getPkgmkSettingFromFile(const string& setting, const string& fileName)
|
||||||
{
|
{
|
||||||
FILE* fp = fopen(fileName.c_str(), "r");
|
FILE* fp = fopen(fileName.c_str(), "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
@ -627,24 +626,24 @@ string InstallTransaction::getPkgDestFromFile(const string& fileName)
|
|||||||
char line[256];
|
char line[256];
|
||||||
while (fgets(line, 256, fp)) {
|
while (fgets(line, 256, fp)) {
|
||||||
s = StringHelper::stripWhiteSpace(line);
|
s = StringHelper::stripWhiteSpace(line);
|
||||||
if (StringHelper::startsWith(s, "PKGMK_PACKAGE_DIR=")) {
|
if (StringHelper::startsWith(s, setting + "=")) {
|
||||||
candidate = s;
|
candidate = s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
string pkgdest = "";
|
string value = "";
|
||||||
if (candidate.length() > 0) {
|
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");
|
FILE* p = popen(cmd.c_str(), "r");
|
||||||
if (p) {
|
if (p) {
|
||||||
fgets(line, 256, p);
|
fgets(line, 256, p);
|
||||||
pkgdest = StringHelper::stripWhiteSpace(line);
|
value = StringHelper::stripWhiteSpace(line);
|
||||||
fclose(p);
|
fclose(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pkgdest;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const list<string>& InstallTransaction::ignoredPackages() const
|
const list<string>& InstallTransaction::ignoredPackages() const
|
||||||
@ -652,7 +651,7 @@ const list<string>& InstallTransaction::ignoredPackages() const
|
|||||||
return m_ignoredPackages;
|
return m_ignoredPackages;
|
||||||
}
|
}
|
||||||
|
|
||||||
string InstallTransaction::pkgDest() const
|
string InstallTransaction::getPkgmkPackageDir()
|
||||||
{
|
{
|
||||||
return m_pkgDest;
|
return getPkgmkSetting("PKGMK_PACKAGE_DIR");
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public:
|
|||||||
const list< pair<string,string> >& missing() const;
|
const list< pair<string,string> >& missing() const;
|
||||||
const list< pair<string, InstallInfo> >& installError() const;
|
const list< pair<string, InstallInfo> >& installError() const;
|
||||||
|
|
||||||
string pkgDest() const;
|
static string getPkgmkPackageDir();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool calculateDependencies();
|
bool calculateDependencies();
|
||||||
@ -109,8 +109,9 @@ private:
|
|||||||
bool update,
|
bool update,
|
||||||
InstallInfo& info ) const;
|
InstallInfo& info ) const;
|
||||||
|
|
||||||
string getPkgDest() const;
|
static string getPkgmkSetting(const string& setting);
|
||||||
static string getPkgDestFromFile(const string& fileName);
|
static string getPkgmkSettingFromFile(const string& setting,
|
||||||
|
const string& fileName);
|
||||||
|
|
||||||
PkgDB* m_pkgDB;
|
PkgDB* m_pkgDB;
|
||||||
DepResolver m_resolver;
|
DepResolver m_resolver;
|
||||||
@ -135,9 +136,6 @@ private:
|
|||||||
list<string> m_depNameList;
|
list<string> m_depNameList;
|
||||||
vector<string> m_depList;
|
vector<string> m_depList;
|
||||||
|
|
||||||
// field for error messages
|
|
||||||
mutable string m_pkgDest;
|
|
||||||
|
|
||||||
// packages requested to be installed not found in the ports tree
|
// packages requested to be installed not found in the ports tree
|
||||||
list< pair<string, string> > m_missingPackages;
|
list< pair<string, string> > m_missingPackages;
|
||||||
|
|
||||||
|
@ -689,7 +689,7 @@ void PrtGet::executeTransaction( InstallTransaction& transaction,
|
|||||||
<< "Make sure it's installed properly" << endl;
|
<< "Make sure it's installed properly" << endl;
|
||||||
} else if ( result == InstallTransaction::PKGDEST_ERROR ) {
|
} else if ( result == InstallTransaction::PKGDEST_ERROR ) {
|
||||||
cout << m_appName << ": error changing to PKGDEST directory "
|
cout << m_appName << ": error changing to PKGDEST directory "
|
||||||
<< transaction.pkgDest() << endl;
|
<< transaction.getPkgmkPackageDir() << endl;
|
||||||
failed = true;
|
failed = true;
|
||||||
} else if ( result == InstallTransaction::PKGADD_FAILURE ) {
|
} else if ( result == InstallTransaction::PKGADD_FAILURE ) {
|
||||||
cout << m_appName << ": error while pkgadding " << endl;
|
cout << m_appName << ": error while pkgadding " << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user