]> git.saurik.com Git - apt.git/blame - apt-pkg/deb/debindexfile.cc
Do not set unhonored DPKG_NO_TSTP variable for dpkg
[apt.git] / apt-pkg / deb / debindexfile.cc
CommitLineData
b2e465d6
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
7db98ffc 3// $Id: debindexfile.cc,v 1.5.2.3 2004/01/04 19:11:00 mdz Exp $
b2e465d6
AL
4/* ######################################################################
5
6 Debian Specific sources.list types and the three sorts of Debian
7 index files.
8
9 ##################################################################### */
10 /*}}}*/
11// Include Files /*{{{*/
ea542140
DK
12#include <config.h>
13
b2e465d6
AL
14#include <apt-pkg/debindexfile.h>
15#include <apt-pkg/debsrcrecords.h>
16#include <apt-pkg/deblistparser.h>
17#include <apt-pkg/debrecords.h>
b2e465d6
AL
18#include <apt-pkg/configuration.h>
19#include <apt-pkg/progress.h>
20#include <apt-pkg/error.h>
21#include <apt-pkg/strutl.h>
22#include <apt-pkg/acquire-item.h>
7db98ffc 23#include <apt-pkg/debmetaindex.h>
233b7808 24#include <apt-pkg/gpgv.h>
453b82a3
DK
25#include <apt-pkg/fileutl.h>
26#include <apt-pkg/indexfile.h>
27#include <apt-pkg/mmap.h>
28#include <apt-pkg/pkgcache.h>
29#include <apt-pkg/cacheiterators.h>
30#include <apt-pkg/pkgcachegen.h>
31#include <apt-pkg/pkgrecords.h>
32#include <apt-pkg/srcrecords.h>
0d29b9d4 33#include <apt-pkg/sptr.h>
e011829d 34
453b82a3
DK
35#include <stdio.h>
36#include <iostream>
2f6a2fbb 37#include <sstream>
453b82a3 38#include <string>
c9443c01 39#include <memory>
b2e465d6
AL
40#include <sys/stat.h>
41 /*}}}*/
42
c9443c01 43// Sources Index /*{{{*/
e3c1cfc7 44debSourcesIndex::debSourcesIndex(IndexTarget const &Target,bool const Trusted) :
c9443c01 45 pkgDebianIndexTargetFile(Target, Trusted), d(NULL)
b2e465d6
AL
46{
47}
c9443c01 48std::string debSourcesIndex::SourceInfo(pkgSrcRecords::Parser const &Record,
b2e465d6
AL
49 pkgSrcRecords::File const &File) const
50{
c9443c01
DK
51 // The result looks like: http://foo/debian/ stable/main src 1.1.1 (dsc)
52 std::string Res = Target.Description;
e3c1cfc7
DK
53 Res.erase(Target.Description.rfind(' '));
54
b2e465d6
AL
55 Res += " ";
56 Res += Record.Package();
57 Res += " ";
58 Res += Record.Version();
59 if (File.Type.empty() == false)
60 Res += " (" + File.Type + ")";
61 return Res;
62}
b2e465d6
AL
63pkgSrcRecords::Parser *debSourcesIndex::CreateSrcParser() const
64{
c9443c01 65 std::string const SourcesURI = IndexFileName();
b0f4b486
MV
66 if (FileExists(SourcesURI))
67 return new debSrcRecordParser(SourcesURI, this);
68 return NULL;
c9443c01
DK
69}
70bool debSourcesIndex::OpenListFile(FileFd &, std::string const &)
71{
72 return true;
73}
74pkgCacheListParser * debSourcesIndex::CreateListParser(FileFd &)
75{
76 return NULL;
77}
78uint8_t debSourcesIndex::GetIndexFlags() const
79{
80 return 0;
b2e465d6
AL
81}
82 /*}}}*/
c9443c01 83// Packages Index /*{{{*/
e3c1cfc7 84debPackagesIndex::debPackagesIndex(IndexTarget const &Target, bool const Trusted) :
c9443c01 85 pkgDebianIndexTargetFile(Target, Trusted), d(NULL)
b2e465d6
AL
86{
87}
c9443c01 88std::string debPackagesIndex::ArchiveInfo(pkgCache::VerIterator const &Ver) const
b2e465d6 89{
c9443c01
DK
90 std::string Res = Target.Description;
91 Res.erase(Target.Description.rfind(' '));
e3c1cfc7 92
b2e465d6
AL
93 Res += " ";
94 Res += Ver.ParentPkg().Name();
95 Res += " ";
c9443c01 96 std::string const Dist = Target.Option(IndexTarget::RELEASE);
e3c1cfc7 97 if (Dist.empty() == false && Dist[Dist.size() - 1] != '/')
dd13742e 98 Res.append(Ver.Arch()).append(" ");
b2e465d6
AL
99 Res += Ver.VerStr();
100 return Res;
101}
c9443c01 102uint8_t debPackagesIndex::GetIndexFlags() const
b2e465d6 103{
c9443c01 104 return 0;
b2e465d6
AL
105}
106 /*}}}*/
c9443c01 107// Translation-* Index /*{{{*/
e3c1cfc7 108debTranslationsIndex::debTranslationsIndex(IndexTarget const &Target) :
c9443c01 109 pkgDebianIndexTargetFile(Target, true), d(NULL)
45df0ad2 110{}
c9443c01 111bool debTranslationsIndex::HasPackages() const
11680bfd 112{
e3c1cfc7 113 return Exists();
a52f938b 114}
c9443c01
DK
115bool debTranslationsIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
116{
117 if (FileExists(FileName))
118 return pkgDebianIndexTargetFile::OpenListFile(Pkg, FileName);
a52f938b
OS
119 return true;
120}
c9443c01 121uint8_t debTranslationsIndex::GetIndexFlags() const
c51c6f08 122{
c9443c01 123 return pkgCache::Flag::NotSource | pkgCache::Flag::NoPackages;
c51c6f08 124}
c9443c01 125std::string debTranslationsIndex::GetArchitecture() const
b2e465d6 126{
c9443c01 127 return std::string();
b2e465d6 128}
c9443c01 129pkgCacheListParser * debTranslationsIndex::CreateListParser(FileFd &Pkg)
b2e465d6 130{
c9443c01
DK
131 if (Pkg.IsOpen() == false)
132 return NULL;
133 _error->PushToStack();
134 pkgCacheListParser * const Parser = new debTranslationsParser(&Pkg);
135 bool const newError = _error->PendingError();
136 _error->MergeWithStack();
137 return newError ? NULL : Parser;
b2e465d6
AL
138}
139 /*}}}*/
c9443c01
DK
140// dpkg/status Index /*{{{*/
141debStatusIndex::debStatusIndex(std::string const &File) : pkgDebianIndexRealFile(File, true), d(NULL)
b2e465d6 142{
b2e465d6 143}
c9443c01 144std::string debStatusIndex::GetArchitecture() const
b2e465d6 145{
c9443c01 146 return std::string();
b2e465d6 147}
c9443c01 148std::string debStatusIndex::GetComponent() const
0d29b9d4 149{
c9443c01 150 return "now";
0d29b9d4 151}
c9443c01 152uint8_t debStatusIndex::GetIndexFlags() const
0d29b9d4 153{
c9443c01 154 return pkgCache::Flag::NotSource;
0d29b9d4 155}
c9443c01
DK
156 /*}}}*/
157// DebPkgFile Index - a single .deb file as an index /*{{{*/
158debDebPkgFileIndex::debDebPkgFileIndex(std::string const &DebFile)
159 : pkgDebianIndexRealFile(DebFile, true), d(NULL), DebFile(DebFile)
0d29b9d4 160{
0d29b9d4 161}
2f6a2fbb 162bool debDebPkgFileIndex::GetContent(std::ostream &content, std::string const &debfile)
0d29b9d4 163{
c9443c01
DK
164 struct stat Buf;
165 if (stat(debfile.c_str(), &Buf) != 0)
166 return false;
167
2f6a2fbb
DK
168 // get the control data out of the deb file via dpkg-deb -I
169 std::string dpkg = _config->Find("Dir::Bin::dpkg","dpkg-deb");
fdff5b03
MV
170 std::vector<const char *> Args;
171 Args.push_back(dpkg.c_str());
fdff5b03 172 Args.push_back("-I");
2f6a2fbb 173 Args.push_back(debfile.c_str());
fdff5b03
MV
174 Args.push_back("control");
175 Args.push_back(NULL);
a9d990a2
MV
176 FileFd PipeFd;
177 pid_t Child;
fdff5b03 178 if(Popen((const char**)&Args[0], PipeFd, Child, FileFd::ReadOnly) == false)
a9d990a2 179 return _error->Error("Popen failed");
2f6a2fbb
DK
180
181 char buffer[1024];
182 do {
183 unsigned long long actual = 0;
184 if (PipeFd.Read(buffer, sizeof(buffer)-1, &actual) == false)
185 return _error->Errno("read", "Failed to read dpkg pipe");
186 if (actual == 0)
187 break;
188 buffer[actual] = '\0';
189 content << buffer;
190 } while(true);
a9d990a2 191 ExecWait(Child, "Popen");
0d29b9d4 192
2f6a2fbb 193 content << "Filename: " << debfile << "\n";
2f6a2fbb
DK
194 content << "Size: " << Buf.st_size << "\n";
195
196 return true;
197}
c9443c01 198bool debDebPkgFileIndex::OpenListFile(FileFd &Pkg, std::string const &FileName)
2f6a2fbb 199{
2f6a2fbb 200 // write the control data to a tempfile
c9443c01 201 if (GetTempFile("deb-file-" + flNotDir(FileName), true, &Pkg) == NULL)
0d29b9d4 202 return false;
2f6a2fbb 203 std::ostringstream content;
c9443c01 204 if (GetContent(content, FileName) == false)
2f6a2fbb
DK
205 return false;
206 std::string const contentstr = content.str();
5465192b
DK
207 if (contentstr.empty())
208 return true;
c9443c01
DK
209 if (Pkg.Write(contentstr.c_str(), contentstr.length()) == false || Pkg.Seek(0) == false)
210 return false;
0d29b9d4
MV
211 return true;
212}
c9443c01
DK
213pkgCacheListParser * debDebPkgFileIndex::CreateListParser(FileFd &Pkg)
214{
215 if (Pkg.IsOpen() == false)
216 return NULL;
217 _error->PushToStack();
218 pkgCacheListParser * const Parser = new debDebFileParser(&Pkg, DebFile);
219 bool const newError = _error->PendingError();
220 _error->MergeWithStack();
221 return newError ? NULL : Parser;
222}
223uint8_t debDebPkgFileIndex::GetIndexFlags() const
224{
225 return pkgCache::Flag::LocalSource;
226}
227std::string debDebPkgFileIndex::GetArchitecture() const
228{
229 return std::string();
230}
231std::string debDebPkgFileIndex::GetComponent() const
232{
233 return "local-deb";
234}
0d29b9d4
MV
235pkgCache::PkgFileIterator debDebPkgFileIndex::FindInCache(pkgCache &Cache) const
236{
c9443c01 237 std::string const FileName = IndexFileName();
0d29b9d4
MV
238 pkgCache::PkgFileIterator File = Cache.FileBegin();
239 for (; File.end() == false; ++File)
240 {
c9443c01 241 if (File.FileName() == NULL || FileName != File.FileName())
0d29b9d4 242 continue;
c9443c01
DK
243 // we can't do size checks here as file size != content size
244 return File;
0d29b9d4 245 }
5465192b 246
0d29b9d4
MV
247 return File;
248}
0d29b9d4 249
c9443c01
DK
250 /*}}}*/
251// DscFile Index - a single .dsc file as an index /*{{{*/
5465192b 252debDscFileIndex::debDscFileIndex(std::string const &DscFile)
c9443c01 253 : pkgDebianIndexRealFile(DscFile, true), d(NULL)
a49e7948
MV
254{
255}
a49e7948
MV
256pkgSrcRecords::Parser *debDscFileIndex::CreateSrcParser() const
257{
c9443c01 258 if (Exists() == false)
a49e7948 259 return NULL;
c9443c01 260 return new debDscRecordParser(File, this);
a49e7948
MV
261}
262 /*}}}*/
5465192b 263
b2e465d6 264// Index File types for Debian /*{{{*/
dce45dbe 265class APT_HIDDEN debIFTypeSrc : public pkgIndexFile::Type
b2e465d6
AL
266{
267 public:
b2e465d6
AL
268 debIFTypeSrc() {Label = "Debian Source Index";};
269};
dce45dbe 270class APT_HIDDEN debIFTypePkg : public pkgIndexFile::Type
b2e465d6
AL
271{
272 public:
c9443c01 273 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE
b2e465d6
AL
274 {
275 return new debRecordParser(File.FileName(),*File.Cache());
276 };
277 debIFTypePkg() {Label = "Debian Package Index";};
278};
dce45dbe 279class APT_HIDDEN debIFTypeTrans : public debIFTypePkg
97234432
MV
280{
281 public:
282 debIFTypeTrans() {Label = "Debian Translation Index";};
283};
dce45dbe 284class APT_HIDDEN debIFTypeStatus : public pkgIndexFile::Type
b2e465d6
AL
285{
286 public:
c9443c01 287 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE
b2e465d6
AL
288 {
289 return new debRecordParser(File.FileName(),*File.Cache());
290 };
291 debIFTypeStatus() {Label = "Debian dpkg status file";};
292};
dce45dbe 293class APT_HIDDEN debIFTypeDebPkgFile : public pkgIndexFile::Type
0d29b9d4
MV
294{
295 public:
c9443c01 296 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &File) const APT_OVERRIDE
0d29b9d4 297 {
2f6a2fbb 298 return new debDebFileRecordParser(File.FileName());
0d29b9d4 299 };
463c8d80 300 debIFTypeDebPkgFile() {Label = "Debian deb file";};
0d29b9d4 301};
dce45dbe 302class APT_HIDDEN debIFTypeDscFile : public pkgIndexFile::Type
a49e7948
MV
303{
304 public:
c9443c01 305 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &DscFile) const APT_OVERRIDE
a49e7948
MV
306 {
307 return new debDscRecordParser(DscFile, NULL);
308 };
463c8d80 309 debIFTypeDscFile() {Label = "Debian dsc file";};
a49e7948 310};
dce45dbe 311class APT_HIDDEN debIFTypeDebianSourceDir : public pkgIndexFile::Type
77da39b9
MV
312{
313 public:
c9443c01 314 virtual pkgSrcRecords::Parser *CreateSrcPkgParser(std::string const &SourceDir) const APT_OVERRIDE
77da39b9 315 {
c9443c01 316 return new debDscRecordParser(SourceDir + std::string("/debian/control"), NULL);
77da39b9 317 };
463c8d80 318 debIFTypeDebianSourceDir() {Label = "Debian control file";};
77da39b9 319};
a49e7948 320
dce45dbe
DK
321APT_HIDDEN debIFTypeSrc _apt_Src;
322APT_HIDDEN debIFTypePkg _apt_Pkg;
323APT_HIDDEN debIFTypeTrans _apt_Trans;
324APT_HIDDEN debIFTypeStatus _apt_Status;
325APT_HIDDEN debIFTypeDebPkgFile _apt_DebPkgFile;
a49e7948 326// file based pseudo indexes
dce45dbe
DK
327APT_HIDDEN debIFTypeDscFile _apt_DscFile;
328APT_HIDDEN debIFTypeDebianSourceDir _apt_DebianSourceDir;
b2e465d6
AL
329
330const pkgIndexFile::Type *debSourcesIndex::GetType() const
331{
332 return &_apt_Src;
333}
334const pkgIndexFile::Type *debPackagesIndex::GetType() const
335{
336 return &_apt_Pkg;
337}
a52f938b
OS
338const pkgIndexFile::Type *debTranslationsIndex::GetType() const
339{
97234432 340 return &_apt_Trans;
a52f938b 341}
b2e465d6
AL
342const pkgIndexFile::Type *debStatusIndex::GetType() const
343{
344 return &_apt_Status;
345}
0d29b9d4
MV
346const pkgIndexFile::Type *debDebPkgFileIndex::GetType() const
347{
348 return &_apt_DebPkgFile;
070536e6 349}
a49e7948
MV
350const pkgIndexFile::Type *debDscFileIndex::GetType() const
351{
352 return &_apt_DscFile;
353}
77da39b9
MV
354const pkgIndexFile::Type *debDebianSourceDirIndex::GetType() const
355{
356 return &_apt_DebianSourceDir;
0d29b9d4 357}
b2e465d6 358 /*}}}*/
862bafea
DK
359
360debStatusIndex::~debStatusIndex() {}
361debPackagesIndex::~debPackagesIndex() {}
362debTranslationsIndex::~debTranslationsIndex() {}
363debSourcesIndex::~debSourcesIndex() {}
364
365debDebPkgFileIndex::~debDebPkgFileIndex() {}
c8a4ce6c 366debDscFileIndex::~debDscFileIndex() {}