]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debsrcrecords.cc
* add "purge" commandline argument, closes: #133421)
[apt.git] / apt-pkg / deb / debsrcrecords.cc
CommitLineData
11e7af84
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
c33b707e 3// $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
11e7af84
AL
4/* ######################################################################
5
6 Debian Source Package Records - Parser implementation for Debian style
7 source indexes
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
12#ifdef __GNUG__
13#pragma implementation "apt-pkg/debsrcrecords.h"
14#endif
15
b2e465d6 16#include <apt-pkg/deblistparser.h>
11e7af84
AL
17#include <apt-pkg/debsrcrecords.h>
18#include <apt-pkg/error.h>
36f610f1 19#include <apt-pkg/strutl.h>
b2e465d6 20#include <apt-pkg/configuration.h>
4ab24e53
MV
21
22using std::max;
11e7af84
AL
23 /*}}}*/
24
25// SrcRecordParser::Binaries - Return the binaries field /*{{{*/
26// ---------------------------------------------------------------------
27/* This member parses the binaries field into a pair of class arrays and
28 returns a list of strings representing all of the components of the
29 binaries field. The returned array need not be freed and will be
b2e465d6
AL
30 reused by the next Binaries function call. This function is commonly
31 used during scanning to find the right package */
11e7af84
AL
32const char **debSrcRecordParser::Binaries()
33{
b2e465d6 34 // This should use Start/Stop too, it is supposed to be efficient after all.
11e7af84 35 string Bins = Sect.FindS("Binary");
c33b707e 36 if (Bins.empty() == true || Bins.length() >= 102400)
11e7af84
AL
37 return 0;
38
d295f24c 39 if (Bins.length() >= BufSize)
c33b707e 40 {
4ab24e53
MV
41 delete [] Buffer;
42 // allocate new size based on buffer (but never smaller than 4000)
19ec5723 43 BufSize = max((unsigned int)4000, max((unsigned int)Bins.length()+1,2*BufSize));
4ab24e53 44 Buffer = new char[BufSize];
c33b707e
AL
45 }
46
4ab24e53
MV
47 strcpy(Buffer,Bins.c_str());
48 if (TokSplitString(',',Buffer,StaticBinList,
b2e465d6
AL
49 sizeof(StaticBinList)/sizeof(StaticBinList[0])) == false)
50 return 0;
c33b707e 51
b2e465d6
AL
52 return (const char **)StaticBinList;
53}
54 /*}}}*/
55// SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
56// ---------------------------------------------------------------------
57/* This member parses the build-depends information and returns a list of
58 package/version records representing the build dependency. The returned
59 array need not be freed and will be reused by the next call to this
60 function */
45430cbf 61bool debSrcRecordParser::BuildDepends(vector<pkgSrcRecords::Parser::BuildDepRec> &BuildDeps, bool ArchOnly)
b2e465d6
AL
62{
63 unsigned int I;
64 const char *Start, *Stop;
65 BuildDepRec rec;
66 const char *fields[] = {"Build-Depends",
67 "Build-Depends-Indep",
68 "Build-Conflicts",
69 "Build-Conflicts-Indep"};
70
71 BuildDeps.clear();
11e7af84 72
b2e465d6 73 for (I = 0; I < 4; I++)
11e7af84 74 {
45430cbf
AL
75 if (ArchOnly && (I == 1 || I == 3))
76 continue;
77
b2e465d6
AL
78 if (Sect.Find(fields[I], Start, Stop) == false)
79 continue;
11e7af84 80
b2e465d6
AL
81 while (1)
82 {
83 Start = debListParser::ParseDepends(Start, Stop,
84 rec.Package,rec.Version,rec.Op,true);
85
86 if (Start == 0)
87 return _error->Error("Problem parsing dependency: %s", fields[I]);
88 rec.Type = I;
89
90 if (rec.Package != "")
91 BuildDeps.push_back(rec);
92
93 if (Start == Stop)
94 break;
95 }
11e7af84
AL
96 }
97
b2e465d6 98 return true;
11e7af84
AL
99}
100 /*}}}*/
36f610f1
AL
101// SrcRecordParser::Files - Return a list of files for this source /*{{{*/
102// ---------------------------------------------------------------------
103/* This parses the list of files and returns it, each file is required to have
104 a complete source package */
105bool debSrcRecordParser::Files(vector<pkgSrcRecords::File> &List)
106{
107 List.erase(List.begin(),List.end());
108
109 string Files = Sect.FindS("Files");
110 if (Files.empty() == true)
111 return false;
112
113 // Stash the / terminated directory prefix
36375005 114 string Base = Sect.FindS("Directory");
36f610f1
AL
115 if (Base.empty() == false && Base[Base.length()-1] != '/')
116 Base += '/';
36375005 117
36f610f1
AL
118 // Iterate over the entire list grabbing each triplet
119 const char *C = Files.c_str();
120 while (*C != 0)
121 {
122 pkgSrcRecords::File F;
123 string Size;
124
125 // Parse each of the elements
126 if (ParseQuoteWord(C,F.MD5Hash) == false ||
127 ParseQuoteWord(C,Size) == false ||
128 ParseQuoteWord(C,F.Path) == false)
129 return _error->Error("Error parsing file record");
130
131 // Parse the size and append the directory
132 F.Size = atoi(Size.c_str());
133 F.Path = Base + F.Path;
b2e465d6
AL
134
135 // Try to guess what sort of file it is we are getting.
136 string::size_type Pos = F.Path.length()-1;
137 while (1)
138 {
139 string::size_type Tmp = F.Path.rfind('.',Pos);
140 if (Tmp == string::npos)
141 break;
142 F.Type = string(F.Path,Tmp+1,Pos-Tmp);
143
144 if (F.Type == "gz" || F.Type == "bz2")
145 {
146 Pos = Tmp-1;
147 continue;
148 }
149
150 break;
151 }
152
36f610f1
AL
153 List.push_back(F);
154 }
155
156 return true;
157}
158 /*}}}*/