diff --git a/ChangeLog b/ChangeLog index 46b9884..f17a683 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* 5.15 27.09.2006 Johannes Winkelmann +- fix PKGMK_PACKAGE_DIR determination + * 5.14 13.09.2006 Johannes Winkelmann - Remove handling of external dependency list - make InstallTransaction::getPkgDest use pkgmk.conf from install-root @@ -6,6 +9,7 @@ - fix bug in "undecided" output of diff (thanks treach) - fix bug in version comperator introduced in 5.13 + * 5.13 08.09.2006 Johannes Winkelmann - Show undecided versions in diff and sysup when using "prefer higher" - fix display bug in "dependent" diff --git a/TODO b/TODO index 56af941..b596cd8 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,3 @@ -- handle 27e < 28 in version comperator - add --rebuild-set to dependent - allow dependency injection for sysup, with previews - prefer toolchain (patch in trac) diff --git a/src/configuration.cpp b/src/configuration.cpp index c2bdc7a..90d8a59 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -108,7 +108,7 @@ void Configuration::addConfig(const string& line, bool configSet, bool configPrepend) { - if (configSet && startwith_nocase( line, "prtdir" )) { + if (configSet && startsWithNoCase( line, "prtdir" )) { m_rootList.clear(); } parseLine(line, configPrepend); @@ -125,7 +125,7 @@ void Configuration::parseLine(const string& line, bool prepend) return; } - if ( startwith_nocase( s, "prtdir" ) ) { + if ( startsWithNoCase( s, "prtdir" ) ) { s = stripWhiteSpace( s.replace( 0, 6, "" ) ); string path = stripWhiteSpace( getValueBefore( s, ':' ) ); string packages = getValue( s, ':' ); @@ -142,58 +142,58 @@ void Configuration::parseLine(const string& line, bool prepend) cerr << "[Config error: can't access " << path << "]" << endl; } - } else if ( startwith_nocase( s, "cachefile" ) ) { + } else if ( startsWithNoCase( s, "cachefile" ) ) { s = stripWhiteSpace( s.replace( 0, 9, "" ) ); m_cacheFile = s; - } else if ( startwith_nocase( s, "writelog" ) ) { + } else if ( startsWithNoCase( s, "writelog" ) ) { s = stripWhiteSpace( s.replace( 0, 8, "" ) ); if ( s == "enabled" ) { // it's already set to false, so we can just enable it. // like this, the command line switch works as well m_writeLog = true; } - } else if ( startwith_nocase( s, "logfile" ) ) { + } else if ( startsWithNoCase( s, "logfile" ) ) { s = stripWhiteSpace( s.replace( 0, 7, "" ) ); m_logFilePattern = s; - } else if ( startwith_nocase( s, "logmode" ) ) { + } else if ( startsWithNoCase( s, "logmode" ) ) { s = stripWhiteSpace( s.replace( 0, 7, "" ) ); if ( s == "append" ) { m_appendLog = true; } - } else if ( startwith_nocase( s, "rmlog_on_success" ) ) { + } else if ( startsWithNoCase( s, "rmlog_on_success" ) ) { s = stripWhiteSpace( s.replace( 0, 16, "" ) ); if ( s == "yes" ) { m_removeLogOnSuccess = true; } - } else if ( startwith_nocase( s, "readme" ) ) { + } else if ( startsWithNoCase( s, "readme" ) ) { s = stripWhiteSpace( s.replace( 0, 6, "" ) ); if ( s == "compact" ) { m_readmeMode = COMPACT_README; } else if ( s == "disabled" ) { m_readmeMode = NO_README; } - } else if ( startwith_nocase( s, "runscripts" ) ) { + } else if ( startsWithNoCase( s, "runscripts" ) ) { s = stripWhiteSpace( s.replace( 0, 10, "" ) ); if ( s == "yes" ) { m_runScripts = true; } - } else if ( startwith_nocase( s, "preferhigher" ) ) { + } else if ( startsWithNoCase( s, "preferhigher" ) ) { s = stripWhiteSpace( s.replace( 0, 12, "" ) ); if ( s == "yes" ) { m_preferHigher = true; } - } else if ( startwith_nocase( s, "useregex" ) ) { + } else if ( startsWithNoCase( s, "useregex" ) ) { s = stripWhiteSpace( s.replace( 0, 8, "" ) ); if ( s == "yes" ) { m_useRegex = true; } - } else if ( startwith_nocase( s, "makecommand" ) ) { + } else if ( startsWithNoCase( s, "makecommand" ) ) { m_makeCommand = stripWhiteSpace( s.replace( 0, 11, "" ) ); - } else if ( startwith_nocase( s, "addcommand" ) ) { + } else if ( startsWithNoCase( s, "addcommand" ) ) { m_addCommand = stripWhiteSpace( s.replace( 0, 10, "" ) ); - } else if ( startwith_nocase( s, "removecommand" ) ) { + } else if ( startsWithNoCase( s, "removecommand" ) ) { m_removeCommand = stripWhiteSpace( s.replace( 0, 13, "" ) ); - } else if ( startwith_nocase( s, "runscriptcommand" ) ) { + } else if ( startsWithNoCase( s, "runscriptcommand" ) ) { m_runscriptCommand = stripWhiteSpace( s.replace( 0, 16, "" ) ); } } diff --git a/src/installtransaction.cpp b/src/installtransaction.cpp index a561c9e..977b9e0 100644 --- a/src/installtransaction.cpp +++ b/src/installtransaction.cpp @@ -169,7 +169,6 @@ InstallTransaction::install( const ArgParser* parser, return SUCCESS; } - /*! Install a single package \param package the package to be installed @@ -291,7 +290,7 @@ InstallTransaction::installPackage( const Package* package, result = PKGMK_FAILURE; } else { // -- update - string pkgdest = getPkgDest(parser->installRoot()); + string pkgdest = getPkgDest(); if ( pkgdest != "" ) { // TODO: don't manipulate pkgdir pkgdir = pkgdest; @@ -586,20 +585,46 @@ InstallTransaction::calcDependencies( ) /* * getPkgDest assumes that you're in the build directory already */ -string InstallTransaction::getPkgDest(const string& installRoot) +string InstallTransaction::getPkgDest() const { string pkgdest = ""; - string cmd = "eval $(fgrep -h 'PKGMK_PACKAGE_DIR=' " - "/usr/bin/pkgmk /etc/pkgmk.conf) " - "&& echo $PKGMK_PACKAGE_DIR"; - FILE* p = popen(cmd.c_str(), "r"); - if ( p ) { - char line[256]; - fgets( line, 256, p ); - pkgdest = line; - pkgdest = StringHelper::stripWhiteSpace( pkgdest ); - pclose( p ); + pkgdest = getPkgDestFromFile("/etc/pkgmk.conf"); + if (pkgdest.size() == 0) { + pkgdest = getPkgDestFromFile("/usr/bin/pkgmk"); } + + m_pkgDest = pkgdest; + return pkgdest; +} + +string InstallTransaction::getPkgDestFromFile(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, "PKGMK_PACKAGE_DIR=")) { + candidate = s; + } + } + fclose(fp); + + string pkgdest = ""; + if (candidate.length() > 0) { + string cmd = "eval " + candidate + " && echo $PKGMK_PACKAGE_DIR"; + FILE* p = popen(cmd.c_str(), "r"); + if (p) { + fgets(line, 256, p); + pkgdest = StringHelper::stripWhiteSpace(line); + fclose(p); + } + } + return pkgdest; } @@ -607,3 +632,8 @@ const list& InstallTransaction::ignoredPackages() const { return m_ignoredPackages; } + +string InstallTransaction::pkgDest() const +{ + return m_pkgDest; +} diff --git a/src/installtransaction.h b/src/installtransaction.h index 4c740c2..0d46e45 100644 --- a/src/installtransaction.h +++ b/src/installtransaction.h @@ -94,6 +94,8 @@ public: const list< pair >& missing() const; const list< pair >& installError() const; + string pkgDest() const; + private: bool calculateDependencies(); void checkDependecies( const Package* package, int depends=-1 ); @@ -103,7 +105,8 @@ private: bool update, InstallInfo& info ) const; - static string getPkgDest(const string& installRoot); + string getPkgDest() const; + static string getPkgDestFromFile(const string& fileName); PkgDB* m_pkgDB; DepResolver m_resolver; @@ -127,6 +130,9 @@ 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/package.cpp b/src/package.cpp index 4c2dd31..e0192c1 100644 --- a/src/package.cpp +++ b/src/package.cpp @@ -199,19 +199,19 @@ void Package::load() const } string::size_type pos = line.find( ':' ); if ( pos != string::npos ) { - if ( startwith_nocase( line, "desc" ) ) { + if ( startsWithNoCase( line, "desc" ) ) { m_data->description = stripWhiteSpace( getValue( line, ':' ) ); - } else if ( startwith_nocase( line, "pack" ) ) { + } else if ( startsWithNoCase( line, "pack" ) ) { m_data->packager = stripWhiteSpace( getValue( line, ':' ) ); - } else if ( startwith_nocase( line, "maint" ) ) { + } else if ( startsWithNoCase( line, "maint" ) ) { m_data->maintainer = stripWhiteSpace( getValue( line, ':' ) ); - } else if ( startwith_nocase( line, "url" ) ) { + } else if ( startsWithNoCase( line, "url" ) ) { m_data->url = stripWhiteSpace( getValue( line, ':' ) ); - } else if ( startwith_nocase( line, "dep" ) ) { + } else if ( startsWithNoCase( line, "dep" ) ) { string depends = stripWhiteSpace( getValue( line, ':' ) ); StringHelper::replaceAll( depends, " ", "," ); @@ -291,7 +291,7 @@ PackageData::PackageData( const string& name_, { generateVersionReleaseString(); - + hasReadme = ( stripWhiteSpace( hasReadme_ ) == "yes" ); hasPreInstall = ( stripWhiteSpace( hasPreInstall_ ) == "yes" ); hasPostInstall = ( stripWhiteSpace( hasPostInstall_ ) == "yes" ); diff --git a/src/prtget.cpp b/src/prtget.cpp index 38ed33a..6f785cd 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -659,7 +659,8 @@ void PrtGet::executeTransaction( InstallTransaction& transaction, cout << m_appName << " couldn't excecute pkgadd. " << "Make sure it's installed properly" << endl; } else if ( result == InstallTransaction::PKGDEST_ERROR ) { - cout << m_appName << ": error changing to directory PKGDEST " << endl; + cout << m_appName << ": error changing to PKGDEST directory " + << transaction.pkgDest() << endl; failed = true; } else if ( result == InstallTransaction::PKGADD_FAILURE ) { cout << m_appName << ": error while pkgadding " << endl; diff --git a/src/stringhelper.cpp b/src/stringhelper.cpp index 5d8853c..2b25d3f 100644 --- a/src/stringhelper.cpp +++ b/src/stringhelper.cpp @@ -78,7 +78,18 @@ string stripWhiteSpace( const string& s ) /*! make sure s1 starts with s2 */ -bool startwith_nocase( const string& s1, const string& s2 ) +bool startsWith( const string& s, const string& with ) +{ + if (s.length() < with.length()) + return false; + + return s.substr(0, with.length()) == with; +} + +/*! + make sure s1 starts with s2 +*/ +bool startsWithNoCase( const string& s1, const string& s2 ) { string::const_iterator p1 = s1.begin(); string::const_iterator p2 = s2.begin(); diff --git a/src/stringhelper.h b/src/stringhelper.h index 42bdc5b..8ab8f4a 100644 --- a/src/stringhelper.h +++ b/src/stringhelper.h @@ -28,7 +28,8 @@ void split( const string& s, char del, int startPos=0, bool useEmpty=true ); string stripWhiteSpace( const string& s ); -bool startwith_nocase( const string& s1, const string& s2 ); +bool startsWith( const string& s, const string& with ); +bool startsWithNoCase( const string& s1, const string& s2 ); string getValue( const string& s, char del ); string getValueBefore( const string& s, char del );