]> git.saurik.com Git - apt.git/blobdiff - ftparchive/contents.cc
don't try to get acquire lock in simulation mode
[apt.git] / ftparchive / contents.cc
index 145a68781bee38b4e46961ccd574331f2ec62f3a..0ce15b3d632b540be5e6b6597fef3514e3b69ae9 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: contents.cc,v 1.2 2001/02/20 07:03:18 jgg Exp $
+// $Id: contents.cc,v 1.4 2003/02/10 07:34:41 doogie Exp $
 /* ######################################################################
    
    contents - Archive contents generator
 /* ######################################################################
    
    contents - Archive contents generator
@@ -13,7 +13,7 @@
    removing the massive sort time overhead.
    
    By breaking all the pathnames into components and storing them 
    removing the massive sort time overhead.
    
    By breaking all the pathnames into components and storing them 
-   separately a space savings is realized by not duplicating the string
+   separately a space saving is realized by not duplicating the string
    over and over again. Ultimately this saving is sacrificed to storage of
    the tree structure itself but the tree structure yields a speed gain
    in the sorting and processing. Ultimately it takes about 5 seconds to
    over and over again. Ultimately this saving is sacrificed to storage of
    the tree structure itself but the tree structure yields a speed gain
    in the sorting and processing. Ultimately it takes about 5 seconds to
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#include "contents.h"
+#include <config.h>
 
 
-#include <apt-pkg/extracttar.h>
+#include <apt-pkg/debfile.h>
+#include <apt-pkg/dirstream.h>
 #include <apt-pkg/error.h>
 #include <apt-pkg/error.h>
+#include <apt-pkg/fileutl.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <malloc.h>    
+
+#include "contents.h"
+
+#include <apti18n.h>
                                                                        /*}}}*/
 
 // GenContents::~GenContents - Free allocated memory                   /*{{{*/
                                                                        /*}}}*/
 
 // GenContents::~GenContents - Free allocated memory                   /*{{{*/
@@ -94,7 +100,7 @@ void *GenContents::Node::operator new(size_t Amount,GenContents *Owner)
    if (Owner->NodeLeft == 0)
    {
       Owner->NodeLeft = 10000;
    if (Owner->NodeLeft == 0)
    {
       Owner->NodeLeft = 10000;
-      Owner->NodePool = (Node *)malloc(Amount*Owner->NodeLeft);
+      Owner->NodePool = static_cast<Node *>(malloc(Amount*Owner->NodeLeft));
       BigBlock *Block = new BigBlock;
       Block->Block = Owner->NodePool;
       Block->Next = Owner->BlockList;
       BigBlock *Block = new BigBlock;
       Block->Block = Owner->NodePool;
       Block->Next = Owner->BlockList;
@@ -227,25 +233,25 @@ void GenContents::Add(const char *Dir,const char *Package)
    
    // The final component if it does not have a trailing /
    if (I - Start >= 1)
    
    // The final component if it does not have a trailing /
    if (I - Start >= 1)
-      Root = Grab(Root,Start,Package);
+      Grab(Root,Start,Package);
 }
                                                                        /*}}}*/
 // GenContents::WriteSpace - Write a given number of white space chars /*{{{*/
 // ---------------------------------------------------------------------
 /* We mod 8 it and write tabs where possible. */
 }
                                                                        /*}}}*/
 // GenContents::WriteSpace - Write a given number of white space chars /*{{{*/
 // ---------------------------------------------------------------------
 /* We mod 8 it and write tabs where possible. */
-void GenContents::WriteSpace(FILE *Out,unsigned int Current,unsigned int Target)
+void GenContents::WriteSpace(std::string &out, size_t Current, size_t Target)
 {
    if (Target <= Current)
       Target = Current + 1;
 {
    if (Target <= Current)
       Target = Current + 1;
-   
+
    /* Now we write tabs so long as the next tab stop would not pass
       the target */
    for (; (Current/8 + 1)*8 < Target; Current = (Current/8 + 1)*8)
    /* Now we write tabs so long as the next tab stop would not pass
       the target */
    for (; (Current/8 + 1)*8 < Target; Current = (Current/8 + 1)*8)
-      fputc('\t',Out);
+      out.append("\t");
 
    // Fill the last bit with spaces
    for (; Current < Target; Current++)
 
    // Fill the last bit with spaces
    for (; Current < Target; Current++)
-      fputc(' ',Out);
+      out.append(" ");
 }
                                                                        /*}}}*/
 // GenContents::Print - Display the tree                               /*{{{*/
 }
                                                                        /*}}}*/
 // GenContents::Print - Display the tree                               /*{{{*/
@@ -254,12 +260,13 @@ void GenContents::WriteSpace(FILE *Out,unsigned int Current,unsigned int Target)
    calls itself and runs over each section of the tree printing out
    the pathname and the hit packages. We use Buf to build the pathname
    summed over all the directory parents of this node. */
    calls itself and runs over each section of the tree printing out
    the pathname and the hit packages. We use Buf to build the pathname
    summed over all the directory parents of this node. */
-void GenContents::Print(FILE *Out)
+void GenContents::Print(FileFd &Out)
 {
    char Buffer[1024];
 {
    char Buffer[1024];
+   Buffer[0] = 0;
    DoPrint(Out,&Root,Buffer);
 }
    DoPrint(Out,&Root,Buffer);
 }
-void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
+void GenContents::DoPrint(FileFd &Out,GenContents::Node *Top, char *Buf)
 {
    if (Top == 0)
       return;
 {
    if (Top == 0)
       return;
@@ -272,54 +279,56 @@ void GenContents::DoPrint(FILE *Out,GenContents::Node *Top, char *Buf)
    if (Top->Path != 0)
    {
       strcat(Buf,Top->Path);
    if (Top->Path != 0)
    {
       strcat(Buf,Top->Path);
-      
+
       // Do not show the item if it is a directory with dups
       if (Top->Path[strlen(Top->Path)-1] != '/' /*|| Top->Dups == 0*/)
       {
       // Do not show the item if it is a directory with dups
       if (Top->Path[strlen(Top->Path)-1] != '/' /*|| Top->Dups == 0*/)
       {
-        fputs(Buf,Out);
-        WriteSpace(Out,strlen(Buf),60);
+        std::string out = Buf;
+        WriteSpace(out, out.length(), 60);
         for (Node *I = Top; I != 0; I = I->Dups)
         {
            if (I != Top)
         for (Node *I = Top; I != 0; I = I->Dups)
         {
            if (I != Top)
-              fputc(',',Out);
-           fputs(I->Package,Out);
+              out.append(",");
+           out.append(I->Package);
         }
         }
-         fputc('\n',Out);
-      }      
-   }   
-   
+         out.append("\n");
+        Out.Write(out.c_str(), out.length());
+      }
+   }
+
    // Go along the directory link
    DoPrint(Out,Top->DirDown,Buf);
    *OldEnd = 0;
    // Go along the directory link
    DoPrint(Out,Top->DirDown,Buf);
    *OldEnd = 0;
-   
+
    // Go right
    DoPrint(Out,Top->BTreeRight,Buf);  
 }
                                                                        /*}}}*/
    // Go right
    DoPrint(Out,Top->BTreeRight,Buf);  
 }
                                                                        /*}}}*/
-
+// ContentsExtract Constructor                                         /*{{{*/
+ContentsExtract::ContentsExtract()
+   : Data(0), MaxSize(0), CurSize(0)
+{
+}
+                                                                       /*}}}*/
+// ContentsExtract Destructor                                          /*{{{*/
+ContentsExtract::~ContentsExtract()
+{
+   free(Data);
+}
+                                                                       /*}}}*/
 // ContentsExtract::Read - Read the archive                            /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 bool ContentsExtract::Read(debDebFile &Deb)
 {
    Reset();
 // ContentsExtract::Read - Read the archive                            /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 bool ContentsExtract::Read(debDebFile &Deb)
 {
    Reset();
-   
-   // Get the archive member and positition the file 
-   const ARArchive::Member *Member = Deb.GotoMember("data.tar.gz");
-   if (Member == 0)
-      return false;
-      
-   // Extract it.
-   ExtractTar Tar(Deb.GetFile(),Member->Size);
-   if (Tar.Go(*this) == false)
-      return false;   
-   return true;   
+   return Deb.ExtractArchive(*this);
 }
                                                                        /*}}}*/
 // ContentsExtract::DoItem - Extract an item                           /*{{{*/
 // ---------------------------------------------------------------------
 /* This just tacks the name onto the end of our memory buffer */
 }
                                                                        /*}}}*/
 // ContentsExtract::DoItem - Extract an item                           /*{{{*/
 // ---------------------------------------------------------------------
 /* This just tacks the name onto the end of our memory buffer */
-bool ContentsExtract::DoItem(Item &Itm,int &Fd)
+bool ContentsExtract::DoItem(Item &Itm, int &/*Fd*/)
 {
    unsigned long Len = strlen(Itm.Name);
    
 {
    unsigned long Len = strlen(Itm.Name);
    
@@ -341,7 +350,7 @@ bool ContentsExtract::DoItem(Item &Itm,int &Fd)
         MaxSize = 512*1024/2;
       char *NewData = (char *)realloc(Data,MaxSize*2);
       if (NewData == 0)
         MaxSize = 512*1024/2;
       char *NewData = (char *)realloc(Data,MaxSize*2);
       if (NewData == 0)
-        return _error->Error("realloc - Failed to allocate memory");
+        return _error->Error(_("realloc - Failed to allocate memory"));
       Data = NewData;
       MaxSize *= 2;
    }
       Data = NewData;
       MaxSize *= 2;
    }
@@ -354,7 +363,7 @@ bool ContentsExtract::DoItem(Item &Itm,int &Fd)
 // ContentsExtract::TakeContents - Load the contents data              /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // ContentsExtract::TakeContents - Load the contents data              /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-bool ContentsExtract::TakeContents(const void *NewData,unsigned long Length)
+bool ContentsExtract::TakeContents(const void *NewData,unsigned long long Length)
 {
    if (Length == 0)
    {
 {
    if (Length == 0)
    {
@@ -372,7 +381,7 @@ bool ContentsExtract::TakeContents(const void *NewData,unsigned long Length)
       
       char *NewData = (char *)realloc(Data,MaxSize*2);
       if (NewData == 0)
       
       char *NewData = (char *)realloc(Data,MaxSize*2);
       if (NewData == 0)
-        return _error->Error("realloc - Failed to allocate memory");
+        return _error->Error(_("realloc - Failed to allocate memory"));
       Data = NewData;
       MaxSize *= 2;
    }
       Data = NewData;
       MaxSize *= 2;
    }
@@ -385,7 +394,7 @@ bool ContentsExtract::TakeContents(const void *NewData,unsigned long Length)
 // ContentsExtract::Add - Read the contents data into the sorter       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
 // ContentsExtract::Add - Read the contents data into the sorter       /*{{{*/
 // ---------------------------------------------------------------------
 /* */
-void ContentsExtract::Add(GenContents &Contents,string Package)
+void ContentsExtract::Add(GenContents &Contents,std::string const &Package)
 {
    const char *Start = Data;
    char *Pkg = Contents.Mystrdup(Package.c_str());
 {
    const char *Start = Data;
    char *Pkg = Contents.Mystrdup(Package.c_str());