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

libapt-pkg issue



Hi all,

I am using libapt-pkg in raspbian (a modified debian for raspberry pi). The problem is that when I want to install a package using libapt-pkg API, the following error occures :

"Internal Error, Pathname to install is not absolute"

I've downloaded the apt source and compiled it with debugging options,
when the code checked the file name for the package, it seems that it expected an absolute path (requiring a '/' at the begining) but the "File"
contains just the .deb file name.

Also when I install the same package in the shell using apt-get install,
everything is ok!

I've attached a sample code that gives this error, Am I doing something wrong?

I've placed .deb files and Packages file in a directory named "debian" in my host and added the following line to sources.list :

    deb http://my_host_address/  debian
(Alos I've tried "deb http://my_host_address/  /debian" )

Can anyone figure out what is the problem?

#include <iostream>
#include <unistd.h>
#include <string.h>

#include <apt-pkg/cachefile.h>
#include <apt-pkg/pkgcache.h>
#include <apt-pkg/packagemanager.h>
#include <apt-pkg/dpkgpm.h>
#include <apt-pkg/error.h>


int main()
{
    if(!pkgInitConfig(*_config))
    {
        std::cout << "Can't init config!" << std::endl;
    }

    if(!pkgInitSystem(*_config, _system))
    {
        std::cout << "Can't init system!" << std::endl;
    }

    pkgCacheFile cache_file;
    pkgCache *cache = cache_file.GetPkgCache();
    if(!cache)
    {
        std::cout << "Can't retrieve cache!" << std::endl;
    }
    pkgDepCache *dep_cache = cache_file.GetDepCache();
    if(!dep_cache)
    {
        std::cout << "Can't retrieve depcache!" << std::endl;
    }
    pkgDPkgPM *pm = new pkgDPkgPM(dep_cache);

    if(!pm)
    {
        std::cout << "Can't create pm!" << std::endl;
    }
    std::cout << "package manager created!" << std::endl;
    GlobalError *err_obj = _GetErrorObj();
    for(pkgCache::PkgIterator package = cache->PkgBegin(); package && !package.end(); package++)
    {
    
//        if(package.Name()=="pac-about")
//            std::cout << package.Name() << std::endl;
       // std::cout << "And inside! ..." << std::endl;

        if( ((*package).CurrentState == pkgCache::State::NotInstalled) &&
            ( strcmp(package.Name(),"pac-about")==0) )
        {
           std::cout << package.Name() << std::endl;
           if(dep_cache->MarkInstall(package))
           {
               std::cout << "Marked" << std::endl;
           }
           break;
        }
    }
    
    if (cache_file.BuildSourceList() == false)
          std::cout << "ERRR" << std::endl; //return false;
    pkgSourceList * const List = cache_file.GetSourceList();

    pkgAcquire Fetcher;


    //Create the text record parser
    pkgRecords Recs(cache_file);
    if (_error->PendingError() == true)
         std::cout << "ERRR" << std::endl; //return false;
    if (pm->GetArchives(&Fetcher,List,&Recs) == false || _error->PendingError() == true)
          std::cout << "ERRR" << std::endl; //return false;


    APT::Progress::PackageManager *progress = APT::Progress::PackageManagerProgressFactory();
    pkgPackageManager::OrderResult rs = pm->DoInstall(progress);
    
    err_obj->DumpErrors(std::cout, GlobalError::MsgType::DEBUG);
    
    if(rs == pkgPackageManager::Completed)
        std::cout << "Completed" << std::endl;
    else if (rs == pkgPackageManager::Failed)
        std::cout << "Failed!" << std::endl;
    else
        std::cout << "InComplete!" << std::endl;
    dep_cache->writeStateFile(NULL);

    return 0;
}

Reply to: