reorder includes: add <config.h> if needed and include it at first
[ntk/apt.git] / apt-pkg / edsp / edspindexfile.cc
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4 The scenario file is designed to work as an intermediate file between
5 APT and the resolver. Its on propose very similar to a dpkg status file
6 ##################################################################### */
7 /*}}}*/
8 // Include Files /*{{{*/
9 #include <config.h>
10
11 #include <apt-pkg/edspindexfile.h>
12 #include <apt-pkg/edsplistparser.h>
13 #include <apt-pkg/sourcelist.h>
14 #include <apt-pkg/configuration.h>
15 #include <apt-pkg/progress.h>
16 #include <apt-pkg/error.h>
17 #include <apt-pkg/strutl.h>
18 #include <apt-pkg/acquire-item.h>
19
20 #include <sys/stat.h>
21 /*}}}*/
22
23 // edspIndex::edspIndex - Constructor /*{{{*/
24 // ---------------------------------------------------------------------
25 /* */
26 edspIndex::edspIndex(string File) : debStatusIndex(File)
27 {
28 }
29 /*}}}*/
30 // StatusIndex::Merge - Load the index file into a cache /*{{{*/
31 bool edspIndex::Merge(pkgCacheGenerator &Gen,OpProgress *Prog) const
32 {
33 FileFd Pkg;
34 if (File != "stdin")
35 Pkg.Open(File, FileFd::ReadOnly);
36 else
37 Pkg.OpenDescriptor(STDIN_FILENO, FileFd::ReadOnly);
38 if (_error->PendingError() == true)
39 return false;
40 edspListParser Parser(&Pkg);
41 if (_error->PendingError() == true)
42 return false;
43
44 if (Prog != NULL)
45 Prog->SubProgress(0,File);
46 if (Gen.SelectFile(File,string(),*this) == false)
47 return _error->Error("Problem with SelectFile %s",File.c_str());
48
49 // Store the IMS information
50 pkgCache::PkgFileIterator CFile = Gen.GetCurFile();
51 struct stat St;
52 if (fstat(Pkg.Fd(),&St) != 0)
53 return _error->Errno("fstat","Failed to stat");
54 CFile->Size = St.st_size;
55 CFile->mtime = St.st_mtime;
56 CFile->Archive = Gen.WriteUniqString("edsp::scenario");
57
58 if (Gen.MergeList(Parser) == false)
59 return _error->Error("Problem with MergeList %s",File.c_str());
60 return true;
61 }
62 /*}}}*/
63 // Index File types for APT /*{{{*/
64 class edspIFType: public pkgIndexFile::Type
65 {
66 public:
67 virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator File) const
68 {
69 // we don't have a record parser for this type as the file is not presistent
70 return NULL;
71 };
72 edspIFType() {Label = "EDSP scenario file";};
73 };
74 static edspIFType _apt_Universe;
75
76 const pkgIndexFile::Type *edspIndex::GetType() const
77 {
78 return &_apt_Universe;
79 }
80 /*}}}*/