prt-get: warn about unclear version decisions when using "prefer higher"

git-svn-id: https://crux.nu/svn/tools/prt-get/trunk@1806 0b5ae1c7-2405-0410-a7fc-ba219f786e1e
This commit is contained in:
Johannes Winkelmann 2006-09-03 16:12:55 +00:00
parent dba4b5e64e
commit 01f7f05e78
5 changed files with 172 additions and 76 deletions

View File

@ -1,3 +1,8 @@
* 0.5.13 00.09.2006 Johannes Winkelmann
- Show undecided versions in diff and sysup when using "prefer higher"
- fix display bug in "dependent"
- fix bug in version comparator
* 0.5.12 00.04.2006 Johannes Winkelmann
- Add 'depinst' in 'help' (thanks Simone)
- Fix compilation on OpenBSD

View File

@ -130,6 +130,13 @@ const bool Package::hasReadme() const
return m_data->hasReadme;
}
/*! \return a typically formatted version-release string */
string Package::versionReleaseString() const
{
load();
return m_data->versionReleaseString;
}
const bool Package::hasPreInstall() const
{
return m_data->hasPreInstall;
@ -235,6 +242,7 @@ void Package::load() const
}
fclose( fp );
m_data->generateVersionReleaseString();
string file = m_data->path + "/" + m_data->name + "/README";
struct stat buf;
@ -282,11 +290,18 @@ PackageData::PackageData( const string& name_,
maintainer( maintainer_ )
{
generateVersionReleaseString();
hasReadme = ( stripWhiteSpace( hasReadme_ ) == "yes" );
hasPreInstall = ( stripWhiteSpace( hasPreInstall_ ) == "yes" );
hasPostInstall = ( stripWhiteSpace( hasPostInstall_ ) == "yes" );
}
void PackageData::generateVersionReleaseString()
{
versionReleaseString = version + "-" + release;
}
void Package::expandShellCommands(std::string& input,
const time_t& timeNow,

View File

@ -56,6 +56,8 @@ public:
const bool hasPreInstall() const;
const bool hasPostInstall() const;
std::string versionReleaseString() const;
void setDependencies( const std::string& dependencies );
@ -96,9 +98,13 @@ struct PackageData
std::string packager;
std::string maintainer;
std::string versionReleaseString;
bool hasReadme;
bool hasPreInstall;
bool hasPostInstall;
void generateVersionReleaseString();
};
#endif /* _PACKAGE_H_ */

View File

@ -40,6 +40,12 @@ using namespace std;
using namespace StringHelper;
using VersionComparator::COMP_RESULT;
using VersionComparator::GREATER;
using VersionComparator::LESS;
using VersionComparator::EQUAL;
using VersionComparator::UNDEFINED;
const string PrtGet::CONF_FILE = SYSCONFDIR"/prt-get.conf";
const string PrtGet::DEFAULT_CACHE_FILE = LOCALSTATEDIR"/lib/pkg/prt-get.cache";
@ -792,14 +798,17 @@ void PrtGet::printQuickDiff()
const map<string, string>& installed = m_pkgDB->installedPackages();
map<string, string>::const_iterator it = installed.begin();
const Package* p = 0;
COMP_RESULT result;
for ( ; it != installed.end(); ++it ) {
if ( !m_locker.isLocked( it->first ) ) {
p = m_repo->getPackage( it->first );
if ( p ) {
if (greaterThan(p->version() + "-" + p->release(),
it->second)) {
result = compareVersions(p->versionReleaseString(),
it->second);
if (result == GREATER) {
cout << it->first.c_str() << " ";
}
// we don't care about undefined diffs here
}
}
}
@ -807,6 +816,28 @@ void PrtGet::printQuickDiff()
}
void PrtGet::printFormattedDiffLine(const string& name,
const string& version1,
const string& version2,
bool isLocked)
{
cout.setf( ios::left, ios::adjustfield );
cout.width( 20 );
cout.fill( ' ' );
cout << name;
cout.width( 20 );
cout.fill( ' ' );
cout << version1;
string locked = "";
if ( isLocked ) {
locked = "locked";
}
cout.width( 20 );
cout.fill( ' ' );
cout << version2 << locked << endl;
}
/*!
print an overview of port which are installed in a different version
than they are in the repository
@ -843,6 +874,7 @@ void PrtGet::printDiff()
map<string, string>::const_iterator it = installed.begin();
const Package* p = 0;
int count = 0;
COMP_RESULT result;
for ( ; it != installed.end(); ++it ) {
p = m_repo->getPackage( it->first );
@ -851,8 +883,9 @@ void PrtGet::printDiff()
continue;
}
if ( greaterThan( p->version() + "-" + p->release(),
it->second ) ) {
result = compareVersions( p->versionReleaseString(),
it->second );
if (result == GREATER ) {
if ( !m_locker.isLocked( it->first ) ||
m_parser->otherArgs().size() > 0 ||
m_parser->all() ) {
@ -862,39 +895,46 @@ void PrtGet::printDiff()
if ( count == 1 ) {
cout << "Differences between installed packages "
<< "and ports tree:\n" << endl;
cout.setf( ios::left, ios::adjustfield );
cout.width( 20 );
cout.fill( ' ' );
cout << "Ports";
cout.width( 20 );
cout.fill( ' ' );
cout << "Installed";
cout.width( 20 );
cout.fill( ' ' );
cout << "Available in the ports tree" << endl << endl;
printFormattedDiffLine("Port",
"Installed",
"Available in the ports tree",
false);
cout << endl;
}
cout.setf( ios::left, ios::adjustfield );
cout.width( 20 );
cout.fill( ' ' );
cout << it->first.c_str();
cout.width( 20 );
cout.fill( ' ' );
cout << it->second.c_str();
printFormattedDiffLine(it->first,
it->second,
p->versionReleaseString(),
m_locker.isLocked( it->first ));
}
} else if (result == UNDEFINED) {
m_undefinedVersionComp.push_back(make_pair(p, it->second));
}
}
}
string locked = "";
if ( m_locker.isLocked( it->first ) ) {
locked = "locked";
}
cout.width( 20 );
cout.fill( ' ' );
cout << (p->version()+"-"+p->release()).c_str()
<< locked << endl;
}
}
if (m_undefinedVersionComp.size()) {
cout << "\n\n" << "Undecidable version differences (use --strict-diff)"
<< endl << endl;
printFormattedDiffLine("Port",
"Installed",
"Available in the ports tree",
false);
cout << endl;
list< pair< const Package*, string > >::iterator it =
m_undefinedVersionComp.begin();
const Package* p;
for (; it != m_undefinedVersionComp.end(); ++it) {
p = it->first;
printFormattedDiffLine(p->name(),
p->versionReleaseString(),
it->second,
false);
}
}
if ( count == 0 ) {
cout << "No differences found" << endl;
}
@ -942,7 +982,6 @@ void PrtGet::evaluateResult( InstallTransaction& transaction,
}
}
const list< pair<string, string> >& missing = transaction.missing();
if ( missing.size() ) {
++errors;
@ -1017,6 +1056,7 @@ void PrtGet::evaluateResult( InstallTransaction& transaction,
cout << endl;
}
// readme's
if ( atLeastOnePackageHasReadme ) {
if ( m_config->readmeMode() == Configuration::VERBOSE_README ) {
@ -1031,9 +1071,25 @@ void PrtGet::evaluateResult( InstallTransaction& transaction,
}
}
}
}
if ( m_undefinedVersionComp.size() ) {
cout << endl
<< "-- Packages with undecidable version "
<< "difference (use --strict-diff)"
<< endl;
list< pair<const Package*, string> >::const_iterator uit =
m_undefinedVersionComp.begin();
const Package * p;
for ( ; uit != m_undefinedVersionComp.end(); ++uit ) {
p = uit->first;
cout << p->name() << " ("
<< p->versionReleaseString()
<< " vs "
<< uit->second << ")" << endl;
}
}
cout << endl;
}
if ( errors == 0 && !interrupted ) {
cout << "prt-get: " << command[1] << " successfully" << endl;
@ -1093,23 +1149,23 @@ void PrtGet::createCache()
/*!
\return true if v1 is greater than v2
*/
bool PrtGet::greaterThan( const string& v1, const string& v2 )
COMP_RESULT PrtGet::compareVersions( const string& v1, const string& v2 )
{
using namespace VersionComparator;
if (v1 == v2) {
return false;
return EQUAL;
}
if (m_parser->preferHigher() ||
(m_config->preferHigher() && !m_parser->strictDiff())) {
COMP_RESULT result = compareVersions(v1, v2);
return (result == GREATER);
COMP_RESULT result = VersionComparator::compareVersions(v1, v2);
return result;
}
return v1 != v2;
if (v1 != v2)
return GREATER;
return LESS;
}
int PrtGet::returnValue() const
@ -1172,7 +1228,7 @@ void PrtGet::printf()
if ( m_pkgDB->isInstalled( p->name() ) ) {
string ip = p->name() + "-" +
m_pkgDB->getPackageVersion( p->name() );
if ( ip == p->name() + "-" + p->version() + "-" + p->release() ) {
if ( ip == p->name() + "-" + p->versionReleaseString() ) {
isInst = "yes";
} else {
isInst = "diff";
@ -1256,7 +1312,7 @@ void PrtGet::printDependent()
initRepo();
string arg = *(m_parser->otherArgs().begin());
if (m_parser) {
if (m_parser->printTree()) {
cout << arg << endl;
printDependent(arg, 2);
} else {
@ -1317,7 +1373,7 @@ void PrtGet::printDependent(const string& dep, int level)
cout << indent << p->name();
if ( m_parser->verbose() > 0 ) {
cout << " " << p->version() << "-" << p->release();
cout << " " << p->versionReleaseString();
}
if ( m_parser->verbose() > 1 ) {
cout << ": " << p->description();
@ -1393,13 +1449,17 @@ void PrtGet::sysup()
const map<string, string>& installed = m_pkgDB->installedPackages();
map<string, string>::const_iterator it = installed.begin();
const Package* p = 0;
COMP_RESULT result;
for ( ; it != installed.end(); ++it ) {
if ( !m_locker.isLocked( it->first ) ) {
p = m_repo->getPackage( it->first );
if ( p ) {
if ( greaterThan( p->version() + "-" + p->release(),
it->second ) ) {
result = compareVersions( p->versionReleaseString(),
it->second );
if (result == GREATER ) {
packagesToUpdate.push_back( it->first );
} else if (result == UNDEFINED ) {
m_undefinedVersionComp.push_back(make_pair(p, it->second));
}
}
}

View File

@ -25,6 +25,7 @@ using namespace std;
#include "signaldispatcher.h"
#include "locker.h"
#include "installtransaction.h"
#include "versioncomparator.h"
/*!
\class PrtGet
@ -117,6 +118,12 @@ protected:
void warnPackageNotFound(InstallTransaction& transaction);
static void printFormattedDiffLine(const string& name,
const string& version1,
const string& version2,
bool locked);
Repository* m_repo;
PkgDB* m_pkgDB;
Configuration* m_config;
@ -144,8 +151,11 @@ protected:
void assertExactArgCount(int count);
void argCountFailure(int count, const string& specifier);
bool greaterThan( const string& v1, const string& v2 );
VersionComparator::COMP_RESULT
compareVersions( const string& v1, const string& v2 );
static bool printFile(const string& file);
std::list< std::pair<const Package*, std::string> > m_undefinedVersionComp;
};
#endif /* _PRTGET_H_ */