Logo Search packages:      
Sourcecode: packagesearch version File versions

void NApt::DumpAvailPackageDB::reloadPackageInformation ( NUtil::IProgressObserver pObserver  )  [virtual]

This reloads the package information.

Parameters:
pLoader the observer where to report the reload progress, 0 if no progress should be reported

Implements NApt::IPackageDB.

Definition at line 84 of file dumpavailpackagedb.cpp.

References _estimatedPackageNum, _packages, NApt::Package::installedState, NApt::Package::installedVersion, SingleHandleMaker::instance(), NApt::Package::name, NApt::Package::parseInformation(), NUtil::IProgressObserver::setProgress(), and NUtil::IProgressObserver::setText().

Referenced by DumpAvailPackageDB().

{
      _packages.clear();
      {
            if (pObserver)
                  pObserver->setText("reading package information");
            
            QString command("apt-cache dumpavail");
            #ifdef __DEBUG
            qDebug("running " + command);
            QTime t;
            t.start();
            #endif
            
            // setup the data for progress infromation
            double increment;
            if ( _estimatedPackageNum == 0 )
                  increment = 0;
            else
                  increment = 80.0 / _estimatedPackageNum;  // update the progress every 1%
            double count = 0;
            int dbgCount = 0;
            int progress = 0;
            
            FILE* pipe = popen(command, "r");
            // current maximum line length of apt-cache dumpavail is around 1700 so 10000 should offer enough safety
            int maximumLineLength = 10000;
            char* chars = new char[maximumLineLength];
            QStringList packageLines;
            while (fgets(chars, maximumLineLength, pipe) != 0)
            {
                  QString line(chars);
                  line.truncate(line.length()-1);     // remove the trailing newline
                  if (!line.isEmpty()) 
                  {
                        packageLines.append(line);
                  } 
                  else 
                  {
                        Package p(packageLines);
                        _packages[SingleHandleMaker::instance()->getHandle(toString(p.name))] = p;
                        packageLines.clear();
                        if (pObserver)
                        {
                              count += increment;
                              ++dbgCount;
                              if (count >= 1)
                              {
                                    ++progress;
                                    pObserver->setProgress(progress);
                                    count -= 1;
                              }
                        }
                  }
            }
            qDebug("size: %d, debug-count: %d", _estimatedPackageNum, dbgCount);
            delete[] chars;
            int exitStatus = pclose(pipe);
            #ifdef __DEBUG
            qDebug( "Time elapsed: %d ms", t.elapsed() );   
            #endif
      }
      // 80% done
      {     
            // reading the status file
            #ifdef __DEBUG
            QTime t;
            t.start();
            #endif
            
            if (pObserver)
            {
                  pObserver->setProgress(80);
                  pObserver->setText("parsing status information");
            }
            
            // setup the data for progress infromation
            double increment;
            if ( _estimatedPackageNum == 0 )
                  increment = 0;
            else
                  increment = 20.0 / _estimatedPackageNum;  // update the progress every 1%
            double count = 0;
            int dbgCount = 0;
            int progress = 80;

            FILE* statusFile = fopen("/var/lib/dpkg/status", "r");
            // current maximum line length of apt-cache dumpavail is around 1700 so 10000 should offer enough safety
            int maximumLineLength = 10000;
            char* chars = new char[maximumLineLength];
            QStringList packageLines;
            Package* pP = 0;
            while (fgets(chars, maximumLineLength, statusFile) != 0)
            {
                  QString line(chars);
                  line.truncate(line.length()-1);     // remove the trailing newline
                  if ( line.isEmpty() )   // package ended
                  {
                        if (pObserver)
                        {
                              count += increment;
                              ++dbgCount;
                              if (count >= 1)
                              {
                                    ++progress;
                                    pObserver->setProgress(progress);
                                    count -= 1;
                              }
                        }
                        // if we gathered some information
                        if (!packageLines.empty())
                        {
                              pP->parseInformation(packageLines);
                        }
                        packageLines.clear();
                  }
                  else if ( line.startsWith("Package: ") )
                  {
                        QString pkg = (line.mid(9));
                        int pkgHandle = SingleHandleMaker::instance()->getHandle(pkg);
                        PackageMap::iterator jt = _packages.find(pkgHandle);
                        if (jt == _packages.end())
                              // insert a new package and return the iterator to it
                              jt = _packages.insert(make_pair(pkgHandle, Package(pkg))).first;
                        pP = &((*jt).second);
                  }
                  else if (line.startsWith("Status: "))
                  {
                        // QString status = (line.mid(8));
                        if (pP != 0)
                        {
                              if (line.endsWith(" installed"))
                                    pP->installedState = Package::INSTALLED;
                        }
                  }
                  else if (line.startsWith("Version: "))
                  {
                        if (pP != 0)
                        {
                              QString installedVersion = (line.mid(9));
                              pP->installedVersion = installedVersion;
                        }
                  }
                  else
                        packageLines.push_back(line);
            }
            qDebug("size: %d, debug-count: %d", _estimatedPackageNum, dbgCount);
            delete[] chars;
            int exitStatus = fclose(statusFile);
      
            // collect the information needed by the package here
            #ifdef __DEBUG
            qDebug( "Time elapsed for /var/lib/dpkg/status: %d ms", t.elapsed() );  
            #endif
      }
      if (pObserver)
            pObserver->setProgress(100);
      _estimatedPackageNum = _packages.size();
}


Generated by  Doxygen 1.6.0   Back to index