]>
Commit | Line | Data |
---|---|---|
6c139d6e AL |
1 | // -*- mode: cpp; mode: fold -*- |
2 | // Description /*{{{*/ | |
b2e465d6 | 3 | // $Id: sourcelist.cc,v 1.18 2001/02/20 07:03:17 jgg Exp $ |
6c139d6e AL |
4 | /* ###################################################################### |
5 | ||
6 | List of Sources | |
7 | ||
8 | ##################################################################### */ | |
9 | /*}}}*/ | |
10 | // Include Files /*{{{*/ | |
11 | #ifdef __GNUG__ | |
094a497d | 12 | #pragma implementation "apt-pkg/sourcelist.h" |
6c139d6e AL |
13 | #endif |
14 | ||
094a497d AL |
15 | #include <apt-pkg/sourcelist.h> |
16 | #include <apt-pkg/error.h> | |
17 | #include <apt-pkg/fileutl.h> | |
18 | #include <apt-pkg/configuration.h> | |
cdcc6d34 | 19 | #include <apt-pkg/strutl.h> |
6c139d6e | 20 | |
b2e465d6 AL |
21 | #include <apti18n.h> |
22 | ||
6c139d6e | 23 | #include <fstream.h> |
b2e465d6 AL |
24 | /*}}}*/ |
25 | ||
26 | // Global list of Item supported | |
27 | static pkgSourceList::Type *ItmList[10]; | |
28 | pkgSourceList::Type **pkgSourceList::Type::GlobalList = ItmList; | |
29 | unsigned long pkgSourceList::Type::GlobalListLen = 0; | |
30 | ||
31 | // Type::Type - Constructor /*{{{*/ | |
32 | // --------------------------------------------------------------------- | |
33 | /* Link this to the global list of items*/ | |
34 | pkgSourceList::Type::Type() | |
35 | { | |
36 | ItmList[GlobalListLen] = this; | |
37 | GlobalListLen++; | |
38 | } | |
39 | /*}}}*/ | |
40 | // Type::GetType - Get a specific meta for a given type /*{{{*/ | |
41 | // --------------------------------------------------------------------- | |
42 | /* */ | |
43 | pkgSourceList::Type *pkgSourceList::Type::GetType(const char *Type) | |
44 | { | |
45 | for (unsigned I = 0; I != GlobalListLen; I++) | |
46 | if (strcmp(GlobalList[I]->Name,Type) == 0) | |
47 | return GlobalList[I]; | |
48 | return 0; | |
49 | } | |
50 | /*}}}*/ | |
51 | // Type::FixupURI - Normalize the URI and check it.. /*{{{*/ | |
52 | // --------------------------------------------------------------------- | |
53 | /* */ | |
54 | bool pkgSourceList::Type::FixupURI(string &URI) const | |
55 | { | |
56 | if (URI.empty() == true) | |
57 | return false; | |
58 | ||
59 | if (URI.find(':') == string::npos) | |
60 | return false; | |
61 | ||
62 | URI = SubstVar(URI,"$(ARCH)",_config->Find("APT::Architecture")); | |
63 | ||
64 | // Make sure that the URN is / postfixed | |
65 | if (URI[URI.size() - 1] != '/') | |
66 | URI += '/'; | |
67 | ||
68 | return true; | |
69 | } | |
70 | /*}}}*/ | |
71 | // Type::ParseLine - Parse a single line /*{{{*/ | |
72 | // --------------------------------------------------------------------- | |
73 | /* This is a generic one that is the 'usual' format for sources.list | |
74 | Weird types may override this. */ | |
75 | bool pkgSourceList::Type::ParseLine(vector<pkgIndexFile *> &List, | |
76 | const char *Buffer, | |
77 | unsigned long CurLine, | |
78 | string File) const | |
79 | { | |
80 | string URI; | |
81 | string Dist; | |
82 | string Section; | |
83 | ||
84 | if (ParseQuoteWord(Buffer,URI) == false) | |
85 | return _error->Error(_("Malformed line %lu in source list %s (URI)"),CurLine,File.c_str()); | |
86 | if (ParseQuoteWord(Buffer,Dist) == false) | |
87 | return _error->Error(_("Malformed line %lu in source list %s (dist)"),CurLine,File.c_str()); | |
88 | ||
89 | if (FixupURI(URI) == false) | |
90 | return _error->Error(_("Malformed line %lu in source list %s (URI parse)"),CurLine,File.c_str()); | |
91 | ||
92 | // Check for an absolute dists specification. | |
93 | if (Dist.empty() == false && Dist[Dist.size() - 1] == '/') | |
94 | { | |
95 | if (ParseQuoteWord(Buffer,Section) == true) | |
96 | return _error->Error(_("Malformed line %lu in source list %s (Absolute dist)"),CurLine,File.c_str()); | |
97 | Dist = SubstVar(Dist,"$(ARCH)",_config->Find("APT::Architecture")); | |
98 | return CreateItem(List,URI,Dist,Section); | |
99 | } | |
100 | ||
101 | // Grab the rest of the dists | |
102 | if (ParseQuoteWord(Buffer,Section) == false) | |
103 | return _error->Error(_("Malformed line %lu in source list %s (dist parse)"),CurLine,File.c_str()); | |
104 | ||
105 | do | |
106 | { | |
107 | if (CreateItem(List,URI,Dist,Section) == false) | |
108 | return false; | |
109 | } | |
110 | while (ParseQuoteWord(Buffer,Section) == true); | |
111 | ||
112 | return true; | |
113 | } | |
6c139d6e AL |
114 | /*}}}*/ |
115 | ||
116 | // SourceList::pkgSourceList - Constructors /*{{{*/ | |
117 | // --------------------------------------------------------------------- | |
118 | /* */ | |
119 | pkgSourceList::pkgSourceList() | |
120 | { | |
121 | } | |
122 | ||
123 | pkgSourceList::pkgSourceList(string File) | |
124 | { | |
125 | Read(File); | |
126 | } | |
127 | /*}}}*/ | |
128 | // SourceList::ReadMainList - Read the main source list from etc /*{{{*/ | |
129 | // --------------------------------------------------------------------- | |
130 | /* */ | |
131 | bool pkgSourceList::ReadMainList() | |
132 | { | |
3b5421b4 | 133 | return Read(_config->FindFile("Dir::Etc::sourcelist")); |
6c139d6e AL |
134 | } |
135 | /*}}}*/ | |
136 | // SourceList::Read - Parse the sourcelist file /*{{{*/ | |
137 | // --------------------------------------------------------------------- | |
138 | /* */ | |
139 | bool pkgSourceList::Read(string File) | |
140 | { | |
141 | // Open the stream for reading | |
142 | ifstream F(File.c_str(),ios::in | ios::nocreate); | |
143 | if (!F != 0) | |
b2e465d6 | 144 | return _error->Errno("ifstream::ifstream",_("Opening %s"),File.c_str()); |
6c139d6e AL |
145 | |
146 | List.erase(List.begin(),List.end()); | |
147 | char Buffer[300]; | |
148 | ||
149 | int CurLine = 0; | |
150 | while (F.eof() == false) | |
151 | { | |
152 | F.getline(Buffer,sizeof(Buffer)); | |
153 | CurLine++; | |
154 | _strtabexpand(Buffer,sizeof(Buffer)); | |
b2e465d6 AL |
155 | |
156 | ||
157 | char *I; | |
158 | for (I = Buffer; *I != 0 && *I != '#'; I++); | |
159 | *I = 0; | |
160 | ||
161 | const char *C = _strstrip(Buffer); | |
6c139d6e AL |
162 | |
163 | // Comment or blank | |
b2e465d6 | 164 | if (C[0] == '#' || C[0] == 0) |
6c139d6e | 165 | continue; |
b2e465d6 | 166 | |
6c139d6e | 167 | // Grok it |
b2e465d6 AL |
168 | string LineType; |
169 | if (ParseQuoteWord(C,LineType) == false) | |
170 | return _error->Error(_("Malformed line %u in source list %s (type)"),CurLine,File.c_str()); | |
6c139d6e | 171 | |
b2e465d6 AL |
172 | Type *Parse = Type::GetType(LineType.c_str()); |
173 | if (Parse == 0) | |
174 | return _error->Error(_("Type '%s' is not known in on line %u in source list %s"),LineType.c_str(),CurLine,File.c_str()); | |
6c139d6e | 175 | |
b2e465d6 AL |
176 | if (Parse->ParseLine(List,C,CurLine,File) == false) |
177 | return false; | |
6c139d6e AL |
178 | } |
179 | return true; | |
180 | } | |
181 | /*}}}*/ | |
b2e465d6 | 182 | // SourceList::FindIndex - Get the index associated with a file /*{{{*/ |
6c139d6e AL |
183 | // --------------------------------------------------------------------- |
184 | /* */ | |
b2e465d6 AL |
185 | bool pkgSourceList::FindIndex(pkgCache::PkgFileIterator File, |
186 | pkgIndexFile *&Found) const | |
6c139d6e | 187 | { |
b2e465d6 | 188 | for (const_iterator I = List.begin(); I != List.end(); I++) |
6c139d6e | 189 | { |
b2e465d6 AL |
190 | if ((*I)->FindInCache(*File.Cache()) == File) |
191 | { | |
192 | Found = *I; | |
193 | return true; | |
194 | } | |
be8922fd | 195 | } |
6c139d6e | 196 | |
b2e465d6 | 197 | return false; |
36375005 AL |
198 | } |
199 | /*}}}*/ | |
b2e465d6 | 200 | // SourceList::GetIndexes - Load the index files into the downloader /*{{{*/ |
6c139d6e AL |
201 | // --------------------------------------------------------------------- |
202 | /* */ | |
b2e465d6 | 203 | bool pkgSourceList::GetIndexes(pkgAcquire *Owner) const |
6c139d6e | 204 | { |
b2e465d6 AL |
205 | for (const_iterator I = List.begin(); I != List.end(); I++) |
206 | if ((*I)->GetIndexes(Owner) == false) | |
207 | return false; | |
208 | return true; | |
6c139d6e AL |
209 | } |
210 | /*}}}*/ |