]> cygwin.com Git - cygwin-apps/setup.git/blob - IniDBBuilderPackage.cc
2002-07-08 Max Bowsher <maxb@ukf.net>
[cygwin-apps/setup.git] / IniDBBuilderPackage.cc
1 /*
2 * Copyright (c) 2002, Robert Collins.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
11 *
12 * Written by Robert Collins <rbtcollins@hotmail.com>
13 *
14 */
15
16 #include "IniDBBuilderPackage.h"
17 #include "IniParseFeedback.h"
18 #include "package_db.h"
19 #include "package_meta.h"
20 #include "package_version.h"
21 #include "cygpackage.h"
22 #include "filemanip.h"
23 #include "version.h"
24 // for strtoul
25 #include <string.h>
26 #include "LogSingleton.h"
27 #include "PackageSpecification.h"
28 #include <algorithm>
29
30 IniDBBuilderPackage::IniDBBuilderPackage (IniParseFeedback const &aFeedback) :
31 cp (0), cbpv (), cspv (), currentSpec (0), currentOrList (0), currentAndList (0), trust (0), _feedback (aFeedback){}
32
33 void
34 IniDBBuilderPackage::buildTimestamp (String const &time)
35 {
36 timestamp = strtoul (time.cstr_oneuse(), 0, 0);
37 }
38
39 void
40 IniDBBuilderPackage::buildVersion (String const &aVersion)
41 {
42 version = aVersion;
43 if (version.size())
44 {
45 String ini_version = canonicalize_version (version);
46 String our_version = canonicalize_version (::version);
47 // XXX useversion < operator
48 if (our_version.compare (ini_version) < 0)
49 _feedback.warning("The current ini file is from a newer version of setup.exe. If you have any trouble installing, please download a fresh version from http://www.cygwin.com/setup.exe");
50 }
51 }
52
53 void dumpAndList (vector<vector <PackageSpecification *> *> *currentAndList);
54
55 void
56 IniDBBuilderPackage::buildPackage (String const &name)
57 {
58 #if DEBUG
59 if (cp)
60 {
61 log (LOG_BABBLE) << "Finished with package " << cp->name << endLog;
62 if (cbpv)
63 {
64 log (LOG_BABBLE) << "Version " << cbpv.Canonical_version() << endLog;
65 log (LOG_BABBLE) << "Depends:" << endLog;
66 dumpAndList (cbpv.depends());
67 }
68 }
69 #endif
70 packagedb db;
71 cp = &db.packages.registerbykey(name);
72 cbpv = cygpackage::createInstance (name);
73 cspv = packageversion ();
74 currentSpec = NULL;
75 currentOrList = NULL;
76 currentAndList = NULL;
77 trust = TRUST_CURR;
78 #if DEBUG
79 log (LOG_BABBLE) << "Created package " << name << endLog;
80 #endif
81 }
82
83 void
84 IniDBBuilderPackage::buildPackageVersion (String const &version)
85 {
86 cbpv.setCanonicalVersion (version);
87 add_correct_version();
88 }
89
90 void
91 IniDBBuilderPackage::buildPackageSDesc (String const &theDesc)
92 {
93 cbpv.set_sdesc(theDesc);
94 }
95
96 void
97 IniDBBuilderPackage::buildPackageLDesc (String const &theDesc)
98 {
99 cbpv.set_ldesc(theDesc);
100 #if DEBUG
101 _feedback.warning(theDesc.cstr_oneuse());
102 #endif
103 }
104
105 void
106 IniDBBuilderPackage::buildPackageInstall (String const &path)
107 {
108 process_src (*cbpv.source(), path);
109 }
110
111 void
112 IniDBBuilderPackage::buildPackageSource (String const &path, String const &size)
113 {
114 packagedb db;
115 /* get an appropriate metadata */
116 csp = db.findSource (PackageSpecification (cbpv.Name()));
117 if (!csp)
118 {
119 /* Copy the existing meta data to a new source package */
120 csp = new packagemeta (*cp);
121 /* delete versions information */
122 csp->versions.clear();
123 csp->desired = packageversion();
124 csp->installed = packageversion();
125 csp->prev = packageversion();
126 csp->curr = packageversion();
127 csp->exp = packageversion();
128 db.sourcePackages.push_back (csp);
129 }
130 /* create a source packageversion */
131 cspv = cygpackage::createInstance (cbpv.Name());
132 cspv.setCanonicalVersion (cbpv.Canonical_version());
133 set<packageversion>::iterator i=find (csp->versions.begin(),
134 csp->versions.end(), cspv);
135 if (i == csp->versions.end())
136 {
137 csp->add_version (cspv);
138 }
139 else
140 cspv = *i;
141
142 if (!cspv.source()->Canonical())
143 cspv.source()->set_canonical (path.cstr_oneuse());
144 cspv.source()->sites.push_back(site(parse_mirror));
145
146 cbpv.setSourcePackageSpecification (PackageSpecification (cspv.Name()));
147
148 // process_src (*cspv.source(), path);
149 setSourceSize (*cspv.source(), size);
150 }
151
152 void
153 IniDBBuilderPackage::buildPackageTrust (int newtrust)
154 {
155 trust = newtrust;
156 if (newtrust != TRUST_UNKNOWN)
157 {
158 cbpv = cygpackage::createInstance (cp->name);
159 cspv = packageversion ();
160 }
161 }
162
163 void
164 IniDBBuilderPackage::buildPackageCategory (String const &name)
165 {
166 cp->add_category (name);
167 }
168
169 void dumpAndList (vector<vector <PackageSpecification *> *> *currentAndList)
170 {
171 if (currentAndList)
172 {
173 log (LOG_BABBLE) << "AND list is:" << endLog;
174 for (vector<vector <PackageSpecification *> *>::const_iterator iAnd =
175 currentAndList->begin(); iAnd != currentAndList->end(); ++iAnd)
176 {
177 for (vector<PackageSpecification *>::const_iterator i=
178 (*iAnd)->begin();
179 i != (*iAnd)->end(); ++i)
180 log(LOG_BABBLE) << **i << " |" << endLog;
181 log (LOG_BABBLE) << "end of OR list," << endLog;
182 }
183 }
184 }
185
186 void
187 IniDBBuilderPackage::buildBeginDepends ()
188 {
189 #if DEBUG
190 log (LOG_BABBLE) << "Beginning of a depends statement for " << cp->name
191 << endLog;
192 dumpAndList (currentAndList);
193 #endif
194 currentSpec = NULL;
195 currentOrList = NULL; /* set by the build AndListNode */
196 currentAndList = cbpv.depends();
197 }
198
199 void
200 IniDBBuilderPackage::buildBeginPreDepends ()
201 {
202 #if DEBUG
203 log (LOG_BABBLE) << "Beginning of a predepends statement" << endLog;
204 dumpAndList (currentAndList);
205 #endif
206 currentSpec = NULL;
207 currentOrList = NULL; /* set by the build AndListNode */
208 currentAndList = cbpv.predepends();
209 }
210
211 void
212 IniDBBuilderPackage::buildPriority (String const &priority)
213 {
214 cp->priority = priority;
215 #if DEBUG
216 log (LOG_BABBLE) << "Package " << cp->name << " is " << priority << endLog;
217 #endif
218 }
219
220 void
221 IniDBBuilderPackage::buildInstalledSize (String const &size)
222 {
223 cbpv.source()->setInstalledSize (atoi(size.cstr_oneuse()));
224 #if DEBUG
225 log (LOG_BABBLE) << "Installed size for " << cp->name << " is " << cpv->bin.installedSize() << endLog;
226 #endif
227 }
228
229 void
230 IniDBBuilderPackage::buildMaintainer (String const &){}
231
232 void
233 IniDBBuilderPackage::buildArchitecture (String const &arch)
234 {
235 cp->architecture = arch;
236 #if DEBUG
237 log (LOG_BABBLE) << "Package " << cp->name << " is for " << arch << " architectures." << endLog;
238 #endif
239 }
240
241 void
242 IniDBBuilderPackage::buildInstallSize (String const &size)
243 {
244 setSourceSize (*cbpv.source(), size);
245 }
246
247 void
248 IniDBBuilderPackage::buildInstallMD5 (unsigned char const * md5)
249 {
250 if (md5 && !cbpv.source()->md5.isSet())
251 cbpv.source()->md5.set(md5);
252 }
253
254 void
255 IniDBBuilderPackage::buildSourceMD5 (unsigned char const * md5)
256 {
257 if (md5 && !cspv.source()->md5.isSet())
258 cspv.source()->md5.set(md5);
259 }
260
261 void
262 IniDBBuilderPackage::buildBeginRecommends ()
263 {
264 #if DEBUG
265 log (LOG_BABBLE) << "Beginning of a recommends statement" << endLog;
266 dumpAndList (currentAndList);
267 #endif
268 currentSpec = NULL;
269 currentOrList = NULL; /* set by the build AndListNode */
270 currentAndList = cbpv.recommends();
271 }
272
273 void
274 IniDBBuilderPackage::buildBeginSuggests ()
275 {
276 #if DEBUG
277 log (LOG_BABBLE) << "Beginning of a suggests statement" << endLog;
278 dumpAndList (currentAndList);
279 #endif
280 currentSpec = NULL;
281 currentOrList = NULL; /* set by the build AndListNode */
282 currentAndList = cbpv.suggests();
283 }
284
285 void
286 IniDBBuilderPackage::buildBeginReplaces ()
287 {
288 #if DEBUG
289 log (LOG_BABBLE) << "Beginning of a replaces statement" << endLog;
290 dumpAndList (currentAndList);
291 #endif
292 currentSpec = NULL;
293 currentOrList = NULL; /* set by the build AndListNode */
294 currentAndList = cbpv.replaces();
295 }
296
297 void
298 IniDBBuilderPackage::buildBeginConflicts ()
299 {
300 #if DEBUG
301 log (LOG_BABBLE) << "Beginning of a conflicts statement" << endLog;
302 dumpAndList (currentAndList);
303 #endif
304 currentSpec = NULL;
305 currentOrList = NULL; /* set by the build AndListNode */
306 currentAndList = cbpv.conflicts();
307 }
308
309 void
310 IniDBBuilderPackage::buildBeginProvides ()
311 {
312 #if DEBUG
313 log (LOG_BABBLE) << "Beginning of a provides statement" << endLog;
314 dumpAndList (currentAndList);
315 #endif
316 currentSpec = NULL;
317 currentOrList = NULL; /* set by the build AndListNode */
318 currentAndList = cbpv.provides();
319 }
320
321 void
322 IniDBBuilderPackage::buildDescription (String const &descline)
323 {
324 if (cbpv)
325 {
326 cbpv.set_ldesc(cbpv.LDesc() + descline + "\n");
327 #if DEBUG
328 log (LOG_BABBLE) << "Description for " << cp->name << ": \"" <<
329 descline << "\"." << endLog;
330 #endif
331 }
332 else
333 _feedback.warning ((String ("Attempt to set description for package")
334 + cp->name
335 + "before creation of a version.").cstr_oneuse());
336 }
337
338 void
339 IniDBBuilderPackage::buildSourceName (String const &name)
340 {
341 if (cbpv)
342 {
343 cbpv.setSourcePackageSpecification (PackageSpecification (name));
344 #if DEBUG
345 log (LOG_BABBLE) << "\"" << cpv->sourcePackageSpecification() <<
346 "\" is the source package for " << cp->name << "." << endLog;
347 #endif
348 }
349 else
350 _feedback.warning ((String ("Attempt to set source for package")
351 + cp->name
352 + "before creation of a version.").cstr_oneuse());
353 }
354
355 void
356 IniDBBuilderPackage::buildSourceNameVersion (String const &version)
357 {
358 if (cbpv)
359 {
360 cbpv.sourcePackageSpecification().setOperator (PackageSpecification::Equals);
361 cbpv.sourcePackageSpecification().setVersion (version);
362 #if DEBUG
363 log (LOG_BABBLE) << "The source version needed for " << cp->name <<
364 " is " << version << "." << endLog;
365 #endif
366 }
367 else
368 _feedback.warning ((String ("Attempt to set source version for package")
369 + cp->name
370 + "before creation of a version.").cstr_oneuse());
371 }
372
373 void
374 IniDBBuilderPackage::buildPackageListAndNode ()
375 {
376 if (currentAndList)
377 {
378 #if DEBUG
379 log (LOG_BABBLE) << "New AND node for a package list" << endLog;
380 if (currentOrList)
381 {
382 ostream &os = log (LOG_BABBLE);
383 os << "Current OR list is :";
384 for (vector<PackageSpecification *>::const_iterator i= currentOrList->begin();
385 i != currentOrList->end(); ++i)
386 os << endl << **i;
387 os << endLog;
388 }
389 #endif
390 currentSpec = NULL;
391 currentOrList = new vector<PackageSpecification *>;
392 currentAndList->push_back (currentOrList);
393 }
394 else
395 _feedback.warning ((String ("Attempt to add And node when no AndList"
396 " present for package ")
397 + cp->name).cstr_oneuse());
398 }
399
400 void
401 IniDBBuilderPackage::buildPackageListOrNode (String const &packageName)
402 {
403 if (currentOrList)
404 {
405 currentSpec = new PackageSpecification (packageName);
406 currentOrList->push_back (currentSpec);
407 #if DEBUG
408 log (LOG_BABBLE) << "New OR node in a package list refers to \"" <<
409 *currentSpec << "\"." << endLog;
410 #endif
411 }
412 else
413 _feedback.warning ((String ("Attempt to set specification for package ")
414 + cp->name
415 + " before creation of a version.").cstr_oneuse());
416 }
417
418 void
419 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators const &_operator)
420 {
421 if (currentSpec)
422 {
423 currentSpec->setOperator (_operator);
424 #if DEBUG
425 log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
426 endLog;
427 #endif
428 }
429 else
430 _feedback.warning ((String ("Attempt to set an operator for package ")
431 + cp->name
432 + " with no current specification.").cstr_oneuse());
433 }
434
435
436 void
437 IniDBBuilderPackage::buildPackageListOperatorVersion (String const &aVersion)
438 {
439 if (currentSpec)
440 {
441 currentSpec->setVersion (aVersion);
442 #if DEBUG
443 log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
444 endLog;
445 #endif
446 }
447 else
448 _feedback.warning ((String ("Attempt to set an operator version for package ")
449 + cp->name
450 + " with no current specification.").cstr_oneuse());
451 }
452
453 /* privates */
454
455 void
456 IniDBBuilderPackage::add_correct_version()
457 {
458 int merged = 0;
459 for (set<packageversion>::iterator n = cp->versions.begin();
460 !merged && n != cp->versions.end(); ++n)
461 if (*n == cbpv )
462 {
463 packageversion ver = *n;
464 /* ASSUMPTIONS:
465 categories and requires are consistent for the same version across
466 all mirrors
467 */
468 /* Copy the binary mirror across if this site claims to have an install */
469 if (cbpv.source()->sites.size() )
470 ver.source()->sites.push_back(site (cbpv.source()->sites.begin()->key));
471 /* Copy the descriptions across */
472 if (cbpv.SDesc ().size() && !n->SDesc ().size())
473 ver.set_sdesc (cbpv.SDesc ());
474 if (cbpv.LDesc ().size() && !n->LDesc ().size())
475 ver.set_ldesc (cbpv.LDesc ());
476 if (cbpv.depends()->size() && !ver.depends ()->size())
477 *ver.depends() = *cbpv.depends();
478 /* TODO: other package lists */
479 /* Prevent dangling references */
480 currentOrList = NULL;
481 currentAndList = NULL;
482 currentSpec = NULL;
483 cbpv = *n;
484 merged = 1;
485 }
486 if (!merged)
487 cp->add_version (cbpv);
488 /* trust setting */
489 switch (trust)
490 {
491 case TRUST_CURR:
492 if (cp->currtimestamp < timestamp)
493 {
494 cp->currtimestamp = timestamp;
495 cp->curr = cbpv;
496 }
497 break;
498 case TRUST_PREV:
499 if (cp->prevtimestamp < timestamp)
500 {
501 cp->prevtimestamp = timestamp;
502 cp->prev = cbpv;
503 }
504 break;
505 case TRUST_TEST:
506 if (cp->exptimestamp < timestamp)
507 {
508 cp->exptimestamp = timestamp;
509 cp->exp = cbpv;
510 }
511 break;
512 }
513 }
514
515 void
516 IniDBBuilderPackage::process_src (packagesource &src, String const &path)
517 {
518 if (!src.Canonical())
519 src.set_canonical (path.cstr_oneuse());
520 src.sites.push_back(site(parse_mirror));
521
522 if (!cbpv.Canonical_version ().size())
523 {
524 fileparse f;
525 if (parse_filename (path, f))
526 {
527 cbpv.setCanonicalVersion (f.ver);
528 add_correct_version ();
529 }
530 }
531 }
532
533 void
534 IniDBBuilderPackage::setSourceSize (packagesource &src, String const &size)
535 {
536 if (!src.size)
537 src.size = atoi(size.cstr_oneuse());
538 }
This page took 0.056335 seconds and 5 git commands to generate.