summaryrefslogtreecommitdiff
path: root/data/_apt7/mmap.diff
blob: 06f4dbac0e757d3b9d0521783fb4def8a89f6162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
diff -ru apt-0.7.20.2/apt-pkg/tagfile.cc apt-0.7.20.2+iPhone/apt-pkg/tagfile.cc
--- apt-0.7.20.2/apt-pkg/tagfile.cc	2009-04-19 02:42:49.000000000 +0000
+++ apt-0.7.20.2+iPhone/apt-pkg/tagfile.cc	2009-04-19 03:28:33.000000000 +0000
@@ -28,11 +28,12 @@
 // ---------------------------------------------------------------------
 /* */
 pkgTagFile::pkgTagFile(FileFd *pFd,unsigned long Size) :
-     Fd(*pFd),
-     Size(Size)
+     Fd(*pFd)
 {
-   if (Fd.IsOpen() == false)
+   if (Fd.IsOpen() == false || Fd.Size() == 0)
    {
+      _error->Discard();
+      Map = NULL;
       Buffer = 0;
       Start = End = Buffer = 0;
       Done = true;
@@ -40,7 +40,8 @@
       return;
    }
    
-   Buffer = new char[Size];
+   Map = new MMap(*pFd, MMap::ReadOnly);
+   Buffer = reinterpret_cast<char *>(Map->Data());
    Start = End = Buffer;
    Done = false;
    iOffset = 0;
@@ -52,36 +53,9 @@
 /* */
 pkgTagFile::~pkgTagFile()
 {
-   delete [] Buffer;
+   delete Map;
 }
 									/*}}}*/
-// TagFile::Resize - Resize the internal buffer				/*{{{*/
-// ---------------------------------------------------------------------
-/* Resize the internal buffer (double it in size). Fail if a maximum size
- * size is reached.
- */
-bool pkgTagFile::Resize()
-{
-   char *tmp;
-   unsigned long EndSize = End - Start;
-
-   // fail is the buffer grows too big
-   if(Size > 1024*1024+1)
-      return false;
-
-   // get new buffer and use it
-   tmp = new char[2*Size];
-   memcpy(tmp, Buffer, Size);
-   Size = Size*2;
-   delete [] Buffer;
-   Buffer = tmp;
-
-   // update the start/end pointers to the new buffer
-   Start = Buffer;
-   End = Start + EndSize;
-   return true;
-}
-
 // TagFile::Step - Advance to the next section				/*{{{*/
 // ---------------------------------------------------------------------
 /* If the Section Scanner fails we refill the buffer and try again. 
@@ -90,15 +64,11 @@
  */
 bool pkgTagFile::Step(pkgTagSection &Tag)
 {
-   while (Tag.Scan(Start,End - Start) == false)
+   if (Tag.Scan(Start,End - Start) == false)
    {
-      if (Fill() == false)
-	 return false;
-      
-      if(Tag.Scan(Start,End - Start))
-	 break;
-
-      if (Resize() == false)
+      if (Start == End)
+         return false;
+      else
 	 return _error->Error(_("Unable to parse package file %s (1)"),
 				 Fd.Name().c_str());
    }
@@ -115,41 +85,11 @@
    then fills the rest from the file */
 bool pkgTagFile::Fill()
 {
-   unsigned long EndSize = End - Start;
-   unsigned long Actual = 0;
-   
-   memmove(Buffer,Start,EndSize);
-   Start = Buffer;
-   End = Buffer + EndSize;
-   
-   if (Done == false)
-   {
-      // See if only a bit of the file is left
-      if (Fd.Read(End,Size - (End - Buffer),&Actual) == false)
-	 return false;
-      if (Actual != Size - (End - Buffer))
-	 Done = true;
-      End += Actual;
-   }
-   
-   if (Done == true)
-   {
-      if (EndSize <= 3 && Actual == 0)
-	 return false;
-      if (Size - (End - Buffer) < 4)
-	 return true;
-      
-      // Append a double new line if one does not exist
-      unsigned int LineCount = 0;
-      for (const char *E = End - 1; E - End < 6 && (*E == '\n' || *E == '\r'); E--)
-	 if (*E == '\n')
-	    LineCount++;
-      for (; LineCount < 2; LineCount++)
-	 *End++ = '\n';
-      
-      return true;
-   }
-   
+   unsigned int Size(Map->Size());
+   End = Buffer + Size;
+   if (iOffset >= Size)
+      return false;
+   Start = Buffer + iOffset;
    return true;
 }
 									/*}}}*/
@@ -171,20 +111,11 @@
    // Reposition and reload..
    iOffset = Offset;
    Done = false;
-   if (Fd.Seek(Offset) == false)
-      return false;
    End = Start = Buffer;
    
    if (Fill() == false)
       return false;
 
-   if (Tag.Scan(Start,End - Start) == true)
-      return true;
-   
-   // This appends a double new line (for the real eof handling)
-   if (Fill() == false)
-      return false;
-   
    if (Tag.Scan(Start,End - Start) == false)
       return _error->Error(_("Unable to parse package file %s (2)"),Fd.Name().c_str());
    
@@ -228,14 +161,16 @@
 
       Stop = (const char *)memchr(Stop,'\n',End - Stop);
       
-      if (Stop == 0)
-	 return false;
+      if (Stop == 0) {
+         Stop = End;
+         goto end;
+      }
       
       for (; Stop+1 < End && Stop[1] == '\r'; Stop++);
 
       // Double newline marks the end of the record
-      if (Stop+1 < End && Stop[1] == '\n')
-      {
+      if (Stop+1 == End || Stop[1] == '\n')
+      end: {
 	 Indexes[TagCount] = Stop - Section;
 	 for (; Stop < End && (Stop[0] == '\n' || Stop[0] == '\r'); Stop++);
 	 return true;
diff -ru apt-0.7.20.2/apt-pkg/tagfile.h apt-0.7.20.2+iPhone/apt-pkg/tagfile.h
--- apt-0.7.20.2/apt-pkg/tagfile.h	2009-02-07 15:09:35.000000000 +0000
+++ apt-0.7.20.2+iPhone/apt-pkg/tagfile.h	2009-04-19 03:04:07.000000000 +0000
@@ -21,6 +21,7 @@
 #define PKGLIB_TAGFILE_H
 
 
+#include <apt-pkg/mmap.h>
 #include <apt-pkg/fileutl.h>
 #include <stdio.h>
     
@@ -71,10 +72,9 @@
    char *End;
    bool Done;
    unsigned long iOffset;
-   unsigned long Size;
+   MMap *Map;
 
    bool Fill();
-   bool Resize();
 
    public: