reorder includes: add <config.h> if needed and include it at first
[ntk/apt.git] / apt-inst / deb / dpkgdb.cc
index 047702f..3112acd 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: dpkgdb.cc,v 1.4 2001/05/27 23:50:42 jgg Exp $
+// $Id: dpkgdb.cc,v 1.7.2.1 2004/01/16 18:58:50 mdz Exp $
 /* ######################################################################
 
    DPKGv1 Database Implemenation
@@ -13,9 +13,7 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#ifdef __GNUG__
-#pragma implementation "apt-pkg/dpkgdb.h"
-#endif
+#include<config.h>
 
 #include <apt-pkg/dpkgdb.h>
 #include <apt-pkg/configuration.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <ctype.h>
-#include <iostream.h>
+#include <iostream>
+#include <apti18n.h>
                                                                        /*}}}*/
+using namespace std;
 
 // EraseDir - Erase A Directory                                                /*{{{*/
 // ---------------------------------------------------------------------
@@ -50,22 +50,22 @@ static bool EraseDir(const char *Dir)
    if (errno == ENOTDIR)
    {
       if (unlink(Dir) != 0)
-        return _error->Errno("unlink","Failed to remove %s",Dir);
+        return _error->Errno("unlink",_("Failed to remove %s"),Dir);
       return true;
    }
    
    // Should not happen
    if (errno != ENOTEMPTY)
-      return _error->Errno("rmdir","Failed to remove %s",Dir);
+      return _error->Errno("rmdir",_("Failed to remove %s"),Dir);
    
    // Purge it using rm
-   int Pid = ExecFork();
+   pid_t Pid = ExecFork();
 
    // Spawn the subprocess
    if (Pid == 0)
    {
       execlp(_config->Find("Dir::Bin::rm","/bin/rm").c_str(),
-            "rm","-rf","--",Dir,0);
+            "rm","-rf","--",Dir,(char *)NULL);
       _exit(100);
    }
    return ExecWait(Pid,_config->Find("dir::bin::rm","/bin/rm").c_str());
@@ -105,20 +105,20 @@ bool debDpkgDB::InitMetaTmp(string &Dir)
 {
    string Tmp = AdminDir + "tmp.ci/";
    if (EraseDir(Tmp.c_str()) == false)
-      return _error->Error("Unable to create %s",Tmp.c_str());
+      return _error->Error(_("Unable to create %s"),Tmp.c_str());
    if (mkdir(Tmp.c_str(),0755) != 0)
-      return _error->Errno("mkdir","Unable to create %s",Tmp.c_str());
+      return _error->Errno("mkdir",_("Unable to create %s"),Tmp.c_str());
    
    // Verify it is on the same filesystem as the main info directory
    dev_t Dev;
    struct stat St;
    if (stat((AdminDir + "info").c_str(),&St) != 0)
-      return _error->Errno("stat","Failed to stat %sinfo",AdminDir.c_str());
+      return _error->Errno("stat",_("Failed to stat %sinfo"),AdminDir.c_str());
    Dev = St.st_dev;
    if (stat(Tmp.c_str(),&St) != 0)
-      return _error->Errno("stat","Failed to stat %s",Tmp.c_str());
+      return _error->Errno("stat",_("Failed to stat %s"),Tmp.c_str());
    if (Dev != St.st_dev)
-      return _error->Error("The info and temp directories need to be on the same filesystem");
+      return _error->Error(_("The info and temp directories need to be on the same filesystem"));
    
    // Done
    Dir = Tmp;
@@ -134,7 +134,7 @@ bool debDpkgDB::ReadyPkgCache(OpProgress &Progress)
 {
    if (Cache != 0)
    {  
-      Progress.OverallProgress(1,1,1,"Reading Package Lists");      
+      Progress.OverallProgress(1,1,1,_("Reading package lists"));      
       return true;
    }
    
@@ -144,7 +144,7 @@ bool debDpkgDB::ReadyPkgCache(OpProgress &Progress)
       CacheMap = 0;
    }
    
-   if (pkgMakeOnlyStatusCache(Progress,&CacheMap) == false)
+   if (pkgCacheGenerator::MakeOnlyStatusCache(&Progress,&CacheMap) == false)
       return false;
    Cache->DropProgress();
    
@@ -175,7 +175,7 @@ bool debDpkgDB::ReadFList(OpProgress &Progress)
       path components */
    string Cwd = SafeGetCWD();
    if (chdir((AdminDir + "info/").c_str()) != 0)
-      return _error->Errno("chdir","Failed to change to the admin dir %sinfo",AdminDir.c_str());
+      return _error->Errno("chdir",_("Failed to change to the admin dir %sinfo"),AdminDir.c_str());
    
    // Allocate a buffer. Anything larger than this buffer will be mmaped
    unsigned long BufSize = 32*1024;
@@ -196,11 +196,11 @@ bool debDpkgDB::ReadFList(OpProgress &Progress)
       pkgFLCache::PkgIterator FlPkg = FList->GetPkg(I.Name(),0,true);
       if (FlPkg.end() == true)
       {
-        _error->Error("Internal Error getting a Package Name");
+        _error->Error(_("Internal error getting a package name"));
         break;
       }
       
-      Progress.OverallProgress(Count,Total,1,"Reading File Listing");
+      Progress.OverallProgress(Count,Total,1,_("Reading file listing"));
      
       // Open the list file
       snprintf(Name,sizeof(Name),"%s.list",I.Name());
@@ -211,9 +211,9 @@ bool debDpkgDB::ReadFList(OpProgress &Progress)
       struct stat Stat;
       if (Fd == -1 || fstat(Fd,&Stat) != 0)
       {
-        _error->Errno("open","Failed to open the list file '%sinfo/%s'. If you "
+        _error->Errno("open",_("Failed to open the list file '%sinfo/%s'. If you "
                       "cannot restore this file then make it empty "
-                      "and immediately re-install the same version of the package!",
+                      "and immediately re-install the same version of the package!"),
                       AdminDir.c_str(),Name);
         break;
       }
@@ -224,7 +224,7 @@ bool debDpkgDB::ReadFList(OpProgress &Progress)
       {
         if (read(Fd,Buffer,Stat.st_size) != Stat.st_size)
         {
-           _error->Errno("read","Failed reading the list file %sinfo/%s",
+           _error->Errno("read",_("Failed reading the list file %sinfo/%s"),
                          AdminDir.c_str(),Name);
            close(Fd);
            break;
@@ -237,7 +237,7 @@ bool debDpkgDB::ReadFList(OpProgress &Progress)
         File = (char *)mmap(0,Stat.st_size,PROT_READ,MAP_PRIVATE,Fd,0);
         if (File == (char *)(-1))
         {
-           _error->Errno("mmap","Failed reading the list file %sinfo/%s",
+           _error->Errno("mmap",_("Failed reading the list file %sinfo/%s"),
                          AdminDir.c_str(),Name);
            close(Fd);
            break;
@@ -261,7 +261,7 @@ bool debDpkgDB::ReadFList(OpProgress &Progress)
                                              FlPkg.Offset(),true,false);
            if (Node.end() == true)
            {
-              _error->Error("Internal Error getting a Node");
+              _error->Error(_("Internal error getting a node"));
               break;
            }
         }
@@ -304,7 +304,7 @@ bool debDpkgDB::ReadDiversions()
    
    FILE *Fd = fopen((AdminDir + "diversions").c_str(),"r");
    if (Fd == 0)
-      return _error->Errno("fopen","Failed to open the diversions file %sdiversions",AdminDir.c_str());
+      return _error->Errno("fopen",_("Failed to open the diversions file %sdiversions"),AdminDir.c_str());
        
    FList->BeginDiverLoad();
    while (1)
@@ -319,24 +319,24 @@ bool debDpkgDB::ReadDiversions()
       if (fgets(To,sizeof(To),Fd) == 0 ||
          fgets(Package,sizeof(Package),Fd) == 0)
       {
-        _error->Error("The diversion file is corrupted");
+        _error->Error(_("The diversion file is corrupted"));
         break;
       }
       
       // Strip the \ns
       unsigned long Len = strlen(From);
       if (Len < 2 || From[Len-1] != '\n')
-        _error->Error("Invalid line in the diversion file: %s",From);
+        _error->Error(_("Invalid line in the diversion file: %s"),From);
       else
         From[Len-1] = 0;
       Len = strlen(To);
       if (Len < 2 || To[Len-1] != '\n')
-        _error->Error("Invalid line in the diversion file: %s",To);
+        _error->Error(_("Invalid line in the diversion file: %s"),To);
       else
         To[Len-1] = 0;     
       Len = strlen(Package);
       if (Len < 2 || Package[Len-1] != '\n')
-        _error->Error("Invalid line in the diversion file: %s",Package);
+        _error->Error(_("Invalid line in the diversion file: %s"),Package);
       else
         Package[Len-1] = 0;
       
@@ -350,14 +350,14 @@ bool debDpkgDB::ReadDiversions()
       pkgFLCache::PkgIterator FlPkg = FList->GetPkg(Package,0,true);
       if (FlPkg.end() == true)
       {
-        _error->Error("Internal Error getting a Package Name");
+        _error->Error(_("Internal error getting a package name"));
         break;
       }
       
       // Install the diversion
       if (FList->AddDiversion(FlPkg,From,To) == false)
       {
-        _error->Error("Internal Error adding a diversion");
+        _error->Error(_("Internal error adding a diversion"));
         break;
       }
    }
@@ -378,10 +378,10 @@ bool debDpkgDB::ReadDiversions()
 bool debDpkgDB::ReadyFileList(OpProgress &Progress)
 {
    if (Cache == 0)
-      return _error->Error("The pkg cache must be initialize first");
+      return _error->Error(_("The pkg cache must be initialized first"));
    if (FList != 0)
    {
-      Progress.OverallProgress(1,1,1,"Reading File List");
+      Progress.OverallProgress(1,1,1,_("Reading file listing"));
       return true;
    }
    
@@ -438,12 +438,12 @@ bool debDpkgDB::ReadConfFiles()
       const char *PkgStart;
       const char *PkgEnd;
       if (Section.Find("Package",PkgStart,PkgEnd) == false)
-        return _error->Error("Failed to find a Package: Header, offset %lu",Offset);
+        return _error->Error(_("Failed to find a Package: header, offset %lu"),Offset);
 
       // Snag a package record for it
       pkgFLCache::PkgIterator FlPkg = FList->GetPkg(PkgStart,PkgEnd,true);
       if (FlPkg.end() == true)
-        return _error->Error("Internal Error getting a Package Name");
+        return _error->Error(_("Internal error getting a package name"));
 
       // Parse the conf file lines
       while (1)
@@ -460,12 +460,12 @@ bool debDpkgDB::ReadConfFiles()
         const char *EndMd5 = StartMd5;
         for (; isspace(*EndMd5) == 0 && EndMd5 < Stop; EndMd5++);
         if (StartMd5 == EndMd5 || Start == End)
-           return _error->Error("Bad ConfFile section in the status file. Offset %lu",Offset);
+           return _error->Error(_("Bad ConfFile section in the status file. Offset %lu"),Offset);
                 
         // Insert a new entry
         unsigned char MD5[16];
         if (Hex2Num(string(StartMd5,EndMd5-StartMd5),MD5,16) == false)
-           return _error->Error("Error parsing MD5. Offset %lu",Offset);
+           return _error->Error(_("Error parsing MD5. Offset %lu"),Offset);
 
         if (FList->AddConfFile(Start,End,FlPkg,MD5) == false)
            return false;