Author: jw
Date: 2006-09-27 17:41:25 +0200 (Wed, 27 Sep 2006)
New Revision: 1947
Modified:
tools/prt-get/trunk/ChangeLog
tools/prt-get/trunk/TODO
tools/prt-get/trunk/src/configuration.cpp
tools/prt-get/trunk/src/installtransaction.cpp
tools/prt-get/trunk/src/installtransaction.h
tools/prt-get/trunk/src/package.cpp
tools/prt-get/trunk/src/prtget.cpp
tools/prt-get/trunk/src/stringhelper.cpp
tools/prt-get/trunk/src/stringhelper.h
Log:
prt-get: rewrite PKGMK_PACKAGE_DIR handling
Modified: tools/prt-get/trunk/ChangeLog
===================================================================
--- tools/prt-get/trunk/ChangeLog 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/ChangeLog 2006-09-27 15:41:25 UTC (rev 1947)
@@ -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"
Modified: tools/prt-get/trunk/TODO
===================================================================
--- tools/prt-get/trunk/TODO 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/TODO 2006-09-27 15:41:25 UTC (rev 1947)
@@ -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)
Modified: tools/prt-get/trunk/src/configuration.cpp
===================================================================
--- tools/prt-get/trunk/src/configuration.cpp 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/configuration.cpp 2006-09-27 15:41:25 UTC (rev 1947)
@@ -108,7 +108,7 @@
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 @@
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 @@
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, "" ) );
}
}
Modified: tools/prt-get/trunk/src/installtransaction.cpp
===================================================================
--- tools/prt-get/trunk/src/installtransaction.cpp 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/installtransaction.cpp 2006-09-27 15:41:25 UTC (rev 1947)
@@ -169,7 +169,6 @@
return SUCCESS;
}
-
/*!
Install a single package
\param package the package to be installed
@@ -291,7 +290,7 @@
result = PKGMK_FAILURE;
} else {
// -- update
- string pkgdest = getPkgDest(parser->installRoot());
+ string pkgdest = getPkgDest();
if ( pkgdest != "" ) {
// TODO: don't manipulate pkgdir
pkgdir = pkgdest;
@@ -586,24 +585,55 @@
/*
* 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;
+}
+
const list<string>& InstallTransaction::ignoredPackages() const
{
return m_ignoredPackages;
}
+
+string InstallTransaction::pkgDest() const
+{
+ return m_pkgDest;
+}
Modified: tools/prt-get/trunk/src/installtransaction.h
===================================================================
--- tools/prt-get/trunk/src/installtransaction.h 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/installtransaction.h 2006-09-27 15:41:25 UTC (rev 1947)
@@ -94,6 +94,8 @@
const list< pair<string,string> >& missing() const;
const list< pair<string, InstallInfo> >& installError() const;
+ string pkgDest() const;
+
private:
bool calculateDependencies();
void checkDependecies( const Package* package, int depends=-1 );
@@ -103,7 +105,8 @@
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 @@
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;
Modified: tools/prt-get/trunk/src/package.cpp
===================================================================
--- tools/prt-get/trunk/src/package.cpp 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/package.cpp 2006-09-27 15:41:25 UTC (rev 1947)
@@ -199,19 +199,19 @@
}
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 @@
{
generateVersionReleaseString();
-
+
hasReadme = ( stripWhiteSpace( hasReadme_ ) == "yes" );
hasPreInstall = ( stripWhiteSpace( hasPreInstall_ ) == "yes" );
hasPostInstall = ( stripWhiteSpace( hasPostInstall_ ) == "yes" );
Modified: tools/prt-get/trunk/src/prtget.cpp
===================================================================
--- tools/prt-get/trunk/src/prtget.cpp 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/prtget.cpp 2006-09-27 15:41:25 UTC (rev 1947)
@@ -659,7 +659,8 @@
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;
Modified: tools/prt-get/trunk/src/stringhelper.cpp
===================================================================
--- tools/prt-get/trunk/src/stringhelper.cpp 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/stringhelper.cpp 2006-09-27 15:41:25 UTC (rev 1947)
@@ -78,8 +78,19 @@
/*!
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();
Modified: tools/prt-get/trunk/src/stringhelper.h
===================================================================
--- tools/prt-get/trunk/src/stringhelper.h 2006-09-27 11:15:15 UTC (rev 1946)
+++ tools/prt-get/trunk/src/stringhelper.h 2006-09-27 15:41:25 UTC (rev 1947)
@@ -28,7 +28,8 @@
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 );