]>
git.saurik.com Git - apt.git/blob - apt-pkg/deb/debsrcrecords.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: debsrcrecords.cc,v 1.6 2004/03/17 05:58:54 mdz Exp $
4 /* ######################################################################
6 Debian Source Package Records - Parser implementation for Debian style
9 ##################################################################### */
11 // Include Files /*{{{*/
14 #include <apt-pkg/deblistparser.h>
15 #include <apt-pkg/debsrcrecords.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/aptconfiguration.h>
19 #include <apt-pkg/srcrecords.h>
20 #include <apt-pkg/tagfile.h>
33 // SrcRecordParser::Binaries - Return the binaries field /*{{{*/
34 // ---------------------------------------------------------------------
35 /* This member parses the binaries field into a pair of class arrays and
36 returns a list of strings representing all of the components of the
37 binaries field. The returned array need not be freed and will be
38 reused by the next Binaries function call. This function is commonly
39 used during scanning to find the right package */
40 const char **debSrcRecordParser::Binaries()
42 const char *Start
, *End
;
43 if (Sect
.Find("Binary", Start
, End
) == false)
45 for (; isspace(*Start
) != 0; ++Start
);
49 StaticBinList
.clear();
51 Buffer
= strndup(Start
, End
- Start
);
55 char* binStartNext
= strchrnul(bin
, ',');
56 char* binEnd
= binStartNext
- 1;
57 for (; isspace(*binEnd
) != 0; --binEnd
)
59 StaticBinList
.push_back(bin
);
60 if (*binStartNext
!= ',')
63 for (bin
= binStartNext
+ 1; isspace(*bin
) != 0; ++bin
);
64 } while (*bin
!= '\0');
65 StaticBinList
.push_back(NULL
);
67 return &StaticBinList
[0];
70 // SrcRecordParser::BuildDepends - Return the Build-Depends information /*{{{*/
71 // ---------------------------------------------------------------------
72 /* This member parses the build-depends information and returns a list of
73 package/version records representing the build dependency. The returned
74 array need not be freed and will be reused by the next call to this
76 bool debSrcRecordParser::BuildDepends(std::vector
<pkgSrcRecords::Parser::BuildDepRec
> &BuildDeps
,
77 bool const &ArchOnly
, bool const &StripMultiArch
)
80 const char *Start
, *Stop
;
82 const char *fields
[] = {"Build-Depends",
83 "Build-Depends-Indep",
85 "Build-Conflicts-Indep"};
89 for (I
= 0; I
< 4; I
++)
91 if (ArchOnly
&& (I
== 1 || I
== 3))
94 if (Sect
.Find(fields
[I
], Start
, Stop
) == false)
99 Start
= debListParser::ParseDepends(Start
, Stop
,
100 rec
.Package
,rec
.Version
,rec
.Op
,true,StripMultiArch
,true);
103 return _error
->Error("Problem parsing dependency: %s", fields
[I
]);
106 if (rec
.Package
!= "")
107 BuildDeps
.push_back(rec
);
117 // SrcRecordParser::Files - Return a list of files for this source /*{{{*/
118 // ---------------------------------------------------------------------
119 /* This parses the list of files and returns it, each file is required to have
120 a complete source package */
121 bool debSrcRecordParser::Files(std::vector
<pkgSrcRecords::File
> &F
)
123 std::vector
<pkgSrcRecords::File2
> F2
;
124 if (Files2(F2
) == false)
126 for (std::vector
<pkgSrcRecords::File2
>::const_iterator f2
= F2
.begin(); f2
!= F2
.end(); ++f2
)
128 pkgSrcRecords::File2 f
;
130 #pragma GCC diagnostic push
131 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
133 f
.MD5Hash
= f2
->MD5Hash
;
136 #pragma GCC diagnostic pop
144 bool debSrcRecordParser::Files2(std::vector
<pkgSrcRecords::File2
> &List
)
148 // Stash the / terminated directory prefix
149 string Base
= Sect
.FindS("Directory");
150 if (Base
.empty() == false && Base
[Base
.length()-1] != '/')
153 std::vector
<std::string
> const compExts
= APT::Configuration::getCompressorExtensions();
155 for (char const * const * type
= HashString::SupportedHashes(); *type
!= NULL
; ++type
)
157 // derive field from checksum type
158 std::string
checksumField("Checksums-");
159 if (strcmp(*type
, "MD5Sum") == 0)
160 checksumField
= "Files"; // historic name for MD5 checksums
162 checksumField
.append(*type
);
164 string
const Files
= Sect
.FindS(checksumField
.c_str());
165 if (Files
.empty() == true)
168 // Iterate over the entire list grabbing each triplet
169 const char *C
= Files
.c_str();
172 string hash
, size
, path
;
174 // Parse each of the elements
175 if (ParseQuoteWord(C
, hash
) == false ||
176 ParseQuoteWord(C
, size
) == false ||
177 ParseQuoteWord(C
, path
) == false)
178 return _error
->Error("Error parsing file record in %s of source package %s", checksumField
.c_str(), Package().c_str());
180 HashString
const hashString(*type
, hash
);
181 if (Base
.empty() == false)
184 // look if we have a record for this file already
185 std::vector
<pkgSrcRecords::File2
>::iterator file
= List
.begin();
186 for (; file
!= List
.end(); ++file
)
187 if (file
->Path
== path
)
190 // we have it already, store the new hash and be done
191 if (file
!= List
.end())
194 // set for compatibility only, so warn users not us
195 #pragma GCC diagnostic push
196 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
198 if (checksumField
== "Files")
199 file
->MD5Hash
= hash
;
201 #pragma GCC diagnostic pop
203 // an error here indicates that we have two different hashes for the same file
204 if (file
->Hashes
.push_back(hashString
) == false)
205 return _error
->Error("Error parsing checksum in %s of source package %s", checksumField
.c_str(), Package().c_str());
209 // we haven't seen this file yet
210 pkgSrcRecords::File2 F
;
212 F
.FileSize
= strtoull(size
.c_str(), NULL
, 10);
213 F
.Hashes
.push_back(hashString
);
216 // set for compatibility only, so warn users not us
217 #pragma GCC diagnostic push
218 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
221 if (checksumField
== "Files")
224 #pragma GCC diagnostic pop
227 // Try to guess what sort of file it is we are getting.
228 string::size_type Pos
= F
.Path
.length()-1;
231 string::size_type Tmp
= F
.Path
.rfind('.',Pos
);
232 if (Tmp
== string::npos
)
234 if (F
.Type
== "tar") {
235 // source v3 has extension 'debian.tar.*' instead of 'diff.*'
236 if (string(F
.Path
, Tmp
+1, Pos
-Tmp
) == "debian")
240 F
.Type
= string(F
.Path
,Tmp
+1,Pos
-Tmp
);
242 if (std::find(compExts
.begin(), compExts
.end(), std::string(".").append(F
.Type
)) != compExts
.end() ||
258 // SrcRecordParser::~SrcRecordParser - Destructor /*{{{*/
259 // ---------------------------------------------------------------------
261 debSrcRecordParser::~debSrcRecordParser()
263 // was allocated via strndup()