[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#809441: apt: provide a global resource for upgradeable packages



On Wed, Dec 30, 2015 at 07:23:55PM +0100, Thilo Six wrote:
> Package: apt
> Version: 1.0.9.8.2
> Severity: wishlist
> 
> Dear Maintainer,
> 
> in Debian there are several tools which calculate the number of
> available pkgs updates and the specific data
> <pkg> <version_old> <version_new>
> on their own.

What does define an available package update for you? The easiest definition
is:

(1) installed package where candidate is newer than installed version

But there is also:

(2) installed package where a newer version exists

and:

(3) installed package that can be upgraded to a newer version.


> This results in several tools here that all do the same thing over and over again.
> (Update notifier e.g. apper, byobu GNU screen wrapper, to include it in status
> line, and so on...)
> 
> Local i have a script which does this once everytime 'update' is run.
> I attach it.
> 
> I would like to ask APT maintainers if you would be interested to include/create
> such a global resource which could be easyly reused by other clients then.

We have an API. An API is there for people to use it. It's not that fast
though, it takes about 400ms to complete for stupid reasons, unless you
are clever -- The one below takes less than 80 ms on my system.

We need to optimise our other API the pkgDepCache, as that incurs a 400ms
overhead or more, as its startup time is linear to the number of dependencies.

-- Source code:

#include <apt-pkg/cachefile.h>
#include <apt-pkg/init.h>
#include <apt-pkg/version.h>
#include <iostream>

int main(void)
{
    struct error_dump {
        ~error_dump() {
            _error->DumpErrors();
        }
    } dumper;
    pkgInitConfig(*_config);
    pkgInitSystem(*_config, _system);

    pkgCacheFile file;

    pkgCache *cache = file.GetPkgCache();
    pkgPolicy *policy = file.GetPolicy();
    int count = 0;
    if (cache == nullptr || policy == nullptr)
        return 1;

    for (auto P = cache->PkgBegin(); !P.end(); ++P) {
        auto I = P.CurrentVer();
        if (I.end())
            continue;

        auto C =policy->GetCandidateVer(P);
        if (C.end())
            continue;
        if (_system->VS->CmpVersion(C.VerStr(), I.VerStr()) > 0)
            count++;
    }

    std::cerr << count << std::endl;
    return 0;
}


-- 
Julian Andres Klode  - Debian Developer, Ubuntu Member

See http://wiki.debian.org/JulianAndresKlode and http://jak-linux.org/.

When replying, only quote what is necessary, and write each reply
directly below the part(s) it pertains to (`inline'). Thank you.


Reply to: