cache the pkgmk.conf settings to avoid repeated disk reads (FS#595)
This commit is contained in:
parent
3a53676253
commit
b5aa185537
@ -36,7 +36,8 @@ Configuration::Configuration( const std::string& configFile,
|
||||
m_useRegex( false ),
|
||||
m_followSoftdeps( false ),
|
||||
m_makeCommand( "" ), m_addCommand( "" ),
|
||||
m_removeCommand( "" ), m_runscriptCommand( "" )
|
||||
m_removeCommand( "" ), m_runscriptCommand( "" ),
|
||||
m_compressionMode( "" ), m_packageDir( "" )
|
||||
{
|
||||
|
||||
}
|
||||
@ -89,6 +90,25 @@ string Configuration::logFilePattern() const
|
||||
return m_logFilePattern;
|
||||
}
|
||||
|
||||
string Configuration::packageDir() const
|
||||
{
|
||||
string value = "";
|
||||
char line[256];
|
||||
string cmd = "eval " + m_packageDir + " && echo \"$PKGMK_PACKAGE_DIR\"";
|
||||
FILE* p = popen(cmd.c_str(), "r");
|
||||
if (p) {
|
||||
fgets(line, 256, p);
|
||||
value = StringHelper::stripWhiteSpace(line);
|
||||
pclose(p);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
string Configuration::compressionMode() const
|
||||
{
|
||||
return ( m_compressionMode == "" ) ? "gz" : m_compressionMode;
|
||||
}
|
||||
|
||||
const list< pair<string, string> >& Configuration::rootList() const
|
||||
{
|
||||
@ -215,6 +235,32 @@ void Configuration::parseLine(const string& line, bool prepend)
|
||||
}
|
||||
}
|
||||
|
||||
bool Configuration::parsePkgmkConf(int readOrder)
|
||||
{
|
||||
string fileName = (readOrder == 1) ? "/etc/pkgmk.conf" : "/usr/bin/pkgmk";
|
||||
FILE* fp = fopen(fileName.c_str(), "r");
|
||||
if (!fp)
|
||||
return false;
|
||||
|
||||
string s;
|
||||
char line[256];
|
||||
while (fgets(line, 256, fp)) {
|
||||
s = StringHelper::stripWhiteSpace(getValueBefore(line,'#'));
|
||||
if ( StringHelper::startsWith(s, "PKGMK_COMPRESSION_MODE=") &&
|
||||
(readOrder==1 || m_compressionMode == "") ) {
|
||||
m_compressionMode = s.substr(23);
|
||||
StringHelper::replaceAll(m_compressionMode,"\"","");
|
||||
StringHelper::replaceAll(m_compressionMode,"'","");
|
||||
} else if ( StringHelper::startsWith(s, "PKGMK_PACKAGE_DIR=") &&
|
||||
(readOrder==1 || m_packageDir == "" ) ) {
|
||||
m_packageDir = s;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
return ( m_compressionMode != "" && m_packageDir != "" );
|
||||
}
|
||||
|
||||
bool Configuration::runScripts() const
|
||||
{
|
||||
return m_runScripts;
|
||||
|
@ -45,6 +45,8 @@ public:
|
||||
bool useRegex() const;
|
||||
bool followSoftdeps() const;
|
||||
|
||||
bool parsePkgmkConf(int readOrder);
|
||||
|
||||
void addConfig(const std::string& line,
|
||||
bool configSet,
|
||||
bool configPrepend);
|
||||
@ -54,6 +56,9 @@ public:
|
||||
std::string removeCommand() const;
|
||||
std::string runscriptCommand() const;
|
||||
|
||||
std::string compressionMode() const;
|
||||
std::string packageDir() const;
|
||||
|
||||
private:
|
||||
std::string m_configFile;
|
||||
const ArgParser* m_parser;
|
||||
@ -80,6 +85,8 @@ private:
|
||||
std::string m_removeCommand;
|
||||
std::string m_runscriptCommand;
|
||||
|
||||
std::string m_compressionMode;
|
||||
std::string m_packageDir;
|
||||
|
||||
void parseLine(const std::string& line, bool prepend=false);
|
||||
};
|
||||
|
@ -308,9 +308,9 @@ const {
|
||||
}
|
||||
|
||||
// -- build
|
||||
string pkgdest = getPkgmkPackageDir();
|
||||
const string builtPkg = package->name() + "#" + package->version() + "-" +
|
||||
package->release() + ".pkg.tar." + getPkgmkCompressionMode();
|
||||
string pkgdest = m_config->packageDir();
|
||||
string builtPkg = package->name() + "#" + package->version() + "-" +
|
||||
package->release() + ".pkg.tar." + m_config->compressionMode();
|
||||
string builtPkgPath = ( pkgdest != "" ) ? pkgdest + "/" + builtPkg :
|
||||
portdir + "/" + builtPkg ;
|
||||
string cmd = PKGMK_DEFAULT_COMMAND;
|
||||
@ -657,62 +657,7 @@ bool InstallTransaction::calcDependencies( )
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
string InstallTransaction::getPkgmkSetting(const string& setting)
|
||||
{
|
||||
string value = "";
|
||||
value = getPkgmkSettingFromFile(setting, "/etc/pkgmk.conf");
|
||||
if (value.size() == 0) {
|
||||
value = getPkgmkSettingFromFile(setting, "/usr/bin/pkgmk");
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
string InstallTransaction::getPkgmkSettingFromFile(const string& setting, const string& fileName)
|
||||
{
|
||||
FILE* fp = fopen(fileName.c_str(), "r");
|
||||
if (!fp)
|
||||
return "";
|
||||
|
||||
string candidate;
|
||||
string s;
|
||||
char line[256];
|
||||
while (fgets(line, 256, fp)) {
|
||||
s = StringHelper::stripWhiteSpace(line);
|
||||
if (StringHelper::startsWith(s, setting + "=")) {
|
||||
candidate = s;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
string value = "";
|
||||
if (candidate.length() > 0) {
|
||||
string cmd = "eval " + candidate + " && echo $" + setting;
|
||||
FILE* p = popen(cmd.c_str(), "r");
|
||||
if (p) {
|
||||
fgets(line, 256, p);
|
||||
value = StringHelper::stripWhiteSpace(line);
|
||||
pclose(p);
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
const list<string>& InstallTransaction::ignoredPackages() const
|
||||
{
|
||||
return m_ignoredPackages;
|
||||
}
|
||||
|
||||
string InstallTransaction::getPkgmkPackageDir()
|
||||
{
|
||||
return getPkgmkSetting("PKGMK_PACKAGE_DIR");
|
||||
}
|
||||
|
||||
string InstallTransaction::getPkgmkCompressionMode()
|
||||
{
|
||||
string value = getPkgmkSetting("PKGMK_COMPRESSION_MODE");
|
||||
|
||||
return value.size() ? value : "gz";
|
||||
}
|
||||
|
@ -91,9 +91,6 @@ public:
|
||||
const list< pair<string,string> >& missing() const;
|
||||
const list< pair<string, InstallInfo> >& installError() const;
|
||||
|
||||
static string getPkgmkPackageDir();
|
||||
static string getPkgmkCompressionMode();
|
||||
|
||||
private:
|
||||
bool calculateDependencies();
|
||||
void checkDependencies( bool greedy, const Package* package, int depends=-1 );
|
||||
@ -104,10 +101,6 @@ private:
|
||||
InstallInfo& info ) const;
|
||||
bool isRequested(const string pname);
|
||||
|
||||
static string getPkgmkSetting(const string& setting);
|
||||
static string getPkgmkSettingFromFile(const string& setting,
|
||||
const string& fileName);
|
||||
|
||||
PkgDB* m_pkgDB;
|
||||
DepResolver m_resolver;
|
||||
const Repository* m_repo;
|
||||
|
@ -609,7 +609,7 @@ void PrtGet::executeTransaction( InstallTransaction& transaction ) {
|
||||
break;
|
||||
case InstallTransaction::PKGDEST_ERROR:
|
||||
cout << m_appName << ": error changing to PKGDEST directory "
|
||||
<< transaction.getPkgmkPackageDir() << endl;
|
||||
<< m_config->packageDir() << endl;
|
||||
failed = true;
|
||||
break;
|
||||
case InstallTransaction::PKGADD_FAILURE:
|
||||
@ -743,6 +743,10 @@ void PrtGet::readConfig() {
|
||||
}
|
||||
}
|
||||
|
||||
if (! m_config->parsePkgmkConf(1)) {
|
||||
m_config->parsePkgmkConf(0);
|
||||
}
|
||||
|
||||
const list< pair<char*, ArgParser::ConfigArgType> >& configData =
|
||||
m_parser->configData();
|
||||
list< pair<char*, ArgParser::ConfigArgType> >::const_iterator it =
|
||||
@ -1925,14 +1929,12 @@ void PrtGet::dumpConfig() {
|
||||
cout.setf( ios::left, ios::adjustfield );
|
||||
cout.width( 20 );
|
||||
cout.fill( ' ' );
|
||||
cout << " Package dir: " << InstallTransaction::getPkgmkPackageDir()
|
||||
<< endl;
|
||||
cout << " Package dir: " << m_config->packageDir() << endl;
|
||||
|
||||
cout.setf( ios::left, ios::adjustfield );
|
||||
cout.width( 20 );
|
||||
cout.fill( ' ' );
|
||||
cout << " Compression mode: "
|
||||
<< InstallTransaction::getPkgmkCompressionMode() << endl;
|
||||
cout << " Compression mode: " << m_config->compressionMode() << endl;
|
||||
|
||||
cout << endl;
|
||||
list< pair<string, string> >::const_iterator it =
|
||||
|
Loading…
Reference in New Issue
Block a user