From 21f2e523141724a841e720661e772f712ff209bd Mon Sep 17 00:00:00 2001 From: John McQuah Date: Wed, 31 May 2023 08:59:55 -0400 Subject: [PATCH] document the interaction between --install-root and 'runscripts yes'; allow command line to override more settings in prt-get.conf; tune installTransaction to avoid lookup during evaluateResult --- configure.in | 2 +- doc/prt-get.8 | 16 +++++++++++++--- src/configuration.cpp | 19 +++++++++++++------ src/installtransaction.cpp | 6 +++++- src/prtget.cpp | 14 ++++++-------- src/repository.cpp | 17 +++-------------- 6 files changed, 41 insertions(+), 33 deletions(-) diff --git a/configure.in b/configure.in index a6ab6f7..0eba8aa 100644 --- a/configure.in +++ b/configure.in @@ -1,7 +1,7 @@ # Process this file with autoconf to produce a configure script. AC_INIT AC_CONFIG_SRCDIR([src/prtget.cpp]) -AM_INIT_AUTOMAKE(prt-get,5.19.5) +AM_INIT_AUTOMAKE(prt-get,5.19.7) dnl Determine default prefix diff --git a/doc/prt-get.8 b/doc/prt-get.8 index 9e80150..9b2fa29 100644 --- a/doc/prt-get.8 +++ b/doc/prt-get.8 @@ -258,9 +258,9 @@ print a list of ports which have in their "Depends on:" line. Use the --softdeps flag to also search the "Optional:" lines for \fB\fP. -By default, output is restricted to ports that are installed. To see all hard -dependencies, add the --all switch; use --recursive to get a recursive list -(without duplication), and --tree to get a nicely indented one. +By default, output is restricted to ports that are installed. To see all +the dependencies, add the --all switch; use --recursive to get a recursive +list (without duplication), and --tree to get a nicely indented one. .TP .B dup [-v] [format] @@ -549,6 +549,16 @@ the requested packages onto a different directory than '/'. In daily usage, this option is not required; it's primarily interesting if you're developing an independent installation. +Some pre- or post-install scripts might not have the intended effect if +invoked as +.B chroot /bin/sh +(the naive way to respect --install-root). +So if you're maintaining an installation on a volume mounted somewhere +other than '/', it might be safer to ensure that your \fBprt\-get.conf(5)\fP +has the line +.B runscripts no +and then run any pre- or post-install scripts by hand. + The setting for --install-root determines which package database is used for reading/writing (so /var/lib/pkg/db must exist), and where the pkg.tar.?z archives get unpacked, but the relevant prt\-get.conf and ports tree are those diff --git a/src/configuration.cpp b/src/configuration.cpp index 5e814db..00e1be2 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -153,7 +153,9 @@ void Configuration::parseLine(const string& line, bool prepend) // 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 ( s == "disabled" ) { + m_writeLog = false; + } } else if ( startsWithNoCase( s, "logfile" ) ) { s = stripWhiteSpace( s.replace( 0, 7, "" ) ); m_logFilePattern = s; @@ -166,7 +168,9 @@ void Configuration::parseLine(const string& line, bool prepend) s = stripWhiteSpace( s.replace( 0, 16, "" ) ); if ( s == "yes" ) { m_removeLogOnSuccess = true; - } + } else if ( s == "no" ) { + m_removeLogOnSuccess = false; + } } else if ( startsWithNoCase( s, "readme" ) ) { s = stripWhiteSpace( s.replace( 0, 6, "" ) ); if ( s == "compact" ) { @@ -178,12 +182,16 @@ void Configuration::parseLine(const string& line, bool prepend) s = stripWhiteSpace( s.replace( 0, 10, "" ) ); if ( s == "yes" ) { m_runScripts = true; - } + } else if ( s == "no" ) { + m_runScripts = false; + } } else if ( startsWithNoCase( s, "preferhigher" ) ) { s = stripWhiteSpace( s.replace( 0, 12, "" ) ); if ( s == "yes" ) { m_preferHigher = true; - } + } else if ( s == "no" ) { + m_preferHigher = false; + } } else if ( startsWithNoCase( s, "useregex" ) ) { s = stripWhiteSpace( s.replace( 0, 8, "" ) ); if ( s == "yes" ) { @@ -193,8 +201,7 @@ void Configuration::parseLine(const string& line, bool prepend) s = stripWhiteSpace( s.replace( 0, 8, "" ) ); if ( s == "yes" ) { m_followSoftdeps = true; - } - if ( s == "no" ) { + } else if ( s == "no" ) { m_followSoftdeps = false; } } else if ( startsWithNoCase( s, "makecommand" ) ) { diff --git a/src/installtransaction.cpp b/src/installtransaction.cpp index 4aa908f..fde3897 100644 --- a/src/installtransaction.cpp +++ b/src/installtransaction.cpp @@ -187,7 +187,8 @@ InstallTransaction::install( const ArgParser* parser, if ( parser->isTest() || (result = installPackage( package, parser, update, info )) == SUCCESS) { - m_installedPackages.push_back( make_pair( package->name(), info)); + m_installedPackages.push_back( make_pair( package->path() + + "/" + package->name(), info)); } else { // log failures are critical @@ -305,6 +306,9 @@ InstallTransaction::installPackage( const Package* package, if (m_config->runscriptCommand() != "") { runscriptCommand = m_config->runscriptCommand(); } + if (parser->installRoot() != "") { + runscriptCommand = "chroot " + parser->installRoot() + runscriptCommand; + } // -- pre-install struct stat statData; diff --git a/src/prtget.cpp b/src/prtget.cpp index 35f8b60..425743a 100644 --- a/src/prtget.cpp +++ b/src/prtget.cpp @@ -1126,15 +1126,13 @@ void PrtGet::evaluateResult( InstallTransaction& transaction, bool atLeastOnePackageHasReadme = false; for ( ; iit != inst.end(); ++iit ) { - if (m_parser->printPath()) { - // TODO: avoid lookup by tuning - // InstallTransaction::installedPackages() - const Package* p = m_repo->getPackage(iit->first); - if (p) { - cout << p->path() << "/"; - } + size_t pos = (iit->first).find_last_of('/'); + if ( m_parser->printPath() || (pos == string::npos) + || (pos+2 > (iit->first).length()) ) { + cout << iit->first; + } else { + cout << (iit->first).substr(pos+1); } - cout << iit->first; if ( iit->second.hasReadme ) { if ( m_config->readmeMode() == Configuration::COMPACT_README ) { diff --git a/src/repository.cpp b/src/repository.cpp index c966003..30e99dd 100644 --- a/src/repository.cpp +++ b/src/repository.cpp @@ -327,20 +327,9 @@ Repository::WriteResult Repository::writeCache( const string& cacheFile ) const Package* p = it->second; // TODO: encode - hasReadme = noStr; - if ( p->hasReadme() ) { - hasReadme = yesStr; - } - - hasPreInstall = noStr; - if ( p->hasPreInstall() ) { - hasPreInstall = yesStr; - } - - hasPostInstall = noStr; - if ( p->hasPostInstall() ) { - hasPostInstall = yesStr; - } + hasReadme = ( p->hasReadme() ) ? yesStr : noStr; + hasPreInstall = ( p->hasPreInstall() ) ? yesStr : noStr; + hasPostInstall = ( p->hasPostInstall() ) ? yesStr : noStr; fprintf( fp, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n", p->name().c_str(),