]> cygwin.com Git - cygwin-apps/setup.git/blob - IniDBBuilderPackage.cc
2002-07-13 Robert Collins <rbtcollins@hotmail.com>
[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.findBinary (PackageSpecification(name));
72 if (!cp)
73 {
74 cp = new packagemeta (name);
75 db.packages.push_back (cp);
76 }
77 cbpv = cygpackage::createInstance (name);
78 cspv = packageversion ();
79 currentSpec = NULL;
80 currentOrList = NULL;
81 currentAndList = NULL;
82 trust = TRUST_CURR;
83 #if DEBUG
84 log (LOG_BABBLE) << "Created package " << name << endLog;
85 #endif
86 }
87
88 void
89 IniDBBuilderPackage::buildPackageVersion (String const &version)
90 {
91 cbpv.setCanonicalVersion (version);
92 add_correct_version();
93 }
94
95 void
96 IniDBBuilderPackage::buildPackageSDesc (String const &theDesc)
97 {
98 cbpv.set_sdesc(theDesc);
99 }
100
101 void
102 IniDBBuilderPackage::buildPackageLDesc (String const &theDesc)
103 {
104 cbpv.set_ldesc(theDesc);
105 #if DEBUG
106 _feedback.warning(theDesc.cstr_oneuse());
107 #endif
108 }
109
110 void
111 IniDBBuilderPackage::buildPackageInstall (String const &path)
112 {
113 process_src (*cbpv.source(), path);
114 }
115
116 void
117 IniDBBuilderPackage::buildPackageSource (String const &path, String const &size)
118 {
119 packagedb db;
120 /* get an appropriate metadata */
121 csp = db.findSource (PackageSpecification (cbpv.Name()));
122 if (!csp)
123 {
124 /* Copy the existing meta data to a new source package */
125 csp = new packagemeta (*cp);
126 /* delete versions information */
127 csp->versions.clear();
128 csp->desired = packageversion();
129 csp->installed = packageversion();
130 csp->prev = packageversion();
131 csp->curr = packageversion();
132 csp->exp = packageversion();
133 db.sourcePackages.push_back (csp);
134 }
135 /* create a source packageversion */
136 cspv = cygpackage::createInstance (cbpv.Name());
137 cspv.setCanonicalVersion (cbpv.Canonical_version());
138 set<packageversion>::iterator i=find (csp->versions.begin(),
139 csp->versions.end(), cspv);
140 if (i == csp->versions.end())
141 {
142 csp->add_version (cspv);
143 }
144 else
145 cspv = *i;
146
147 if (!cspv.source()->Canonical())
148 cspv.source()->set_canonical (path.cstr_oneuse());
149 cspv.source()->sites.push_back(site(parse_mirror));
150
151 cbpv.setSourcePackageSpecification (PackageSpecification (cspv.Name()));
152
153 // process_src (*cspv.source(), path);
154 setSourceSize (*cspv.source(), size);
155 }
156
157 void
158 IniDBBuilderPackage::buildPackageTrust (int newtrust)
159 {
160 trust = newtrust;
161 if (newtrust != TRUST_UNKNOWN)
162 {
163 cbpv = cygpackage::createInstance (cp->name);
164 cspv = packageversion ();
165 }
166 }
167
168 void
169 IniDBBuilderPackage::buildPackageCategory (String const &name)
170 {
171 cp->add_category (name);
172 }
173
174 void dumpAndList (vector<vector <PackageSpecification *> *> *currentAndList)
175 {
176 if (currentAndList)
177 {
178 log (LOG_BABBLE) << "AND list is:" << endLog;
179 for (vector<vector <PackageSpecification *> *>::const_iterator iAnd =
180 currentAndList->begin(); iAnd != currentAndList->end(); ++iAnd)
181 {
182 for (vector<PackageSpecification *>::const_iterator i=
183 (*iAnd)->begin();
184 i != (*iAnd)->end(); ++i)
185 log(LOG_BABBLE) << **i << " |" << endLog;
186 log (LOG_BABBLE) << "end of OR list," << endLog;
187 }
188 }
189 }
190
191 void
192 IniDBBuilderPackage::buildBeginDepends ()
193 {
194 #if DEBUG
195 log (LOG_BABBLE) << "Beginning of a depends statement for " << cp->name
196 << endLog;
197 dumpAndList (currentAndList);
198 #endif
199 currentSpec = NULL;
200 currentOrList = NULL; /* set by the build AndListNode */
201 currentAndList = cbpv.depends();
202 }
203
204 void
205 IniDBBuilderPackage::buildBeginPreDepends ()
206 {
207 #if DEBUG
208 log (LOG_BABBLE) << "Beginning of a predepends statement" << endLog;
209 dumpAndList (currentAndList);
210 #endif
211 currentSpec = NULL;
212 currentOrList = NULL; /* set by the build AndListNode */
213 currentAndList = cbpv.predepends();
214 }
215
216 void
217 IniDBBuilderPackage::buildPriority (String const &priority)
218 {
219 cp->priority = priority;
220 #if DEBUG
221 log (LOG_BABBLE) << "Package " << cp->name << " is " << priority << endLog;
222 #endif
223 }
224
225 void
226 IniDBBuilderPackage::buildInstalledSize (String const &size)
227 {
228 cbpv.source()->setInstalledSize (atoi(size.cstr_oneuse()));
229 #if DEBUG
230 log (LOG_BABBLE) << "Installed size for " << cp->name << " is " << cpv->bin.installedSize() << endLog;
231 #endif
232 }
233
234 void
235 IniDBBuilderPackage::buildMaintainer (String const &){}
236
237 /* TODO: we can multiple arch's for a given package,
238 and it may befor either source or binary, so we need to either set both
239 or track a third current package that points to whether we altering source
240 or binary at the moment
241 */
242 void
243 IniDBBuilderPackage::buildArchitecture (String const &arch)
244 {
245 cp->architecture = arch;
246 #if DEBUG
247 log (LOG_BABBLE) << "Package " << cp->name << " is for " << arch << " architectures." << endLog;
248 #endif
249 }
250
251 void
252 IniDBBuilderPackage::buildInstallSize (String const &size)
253 {
254 setSourceSize (*cbpv.source(), size);
255 }
256
257 void
258 IniDBBuilderPackage::buildInstallMD5 (unsigned char const * md5)
259 {
260 if (md5 && !cbpv.source()->md5.isSet())
261 cbpv.source()->md5.set(md5);
262 }
263
264 void
265 IniDBBuilderPackage::buildSourceMD5 (unsigned char const * md5)
266 {
267 if (md5 && !cspv.source()->md5.isSet())
268 cspv.source()->md5.set(md5);
269 }
270
271 void
272 IniDBBuilderPackage::buildBeginRecommends ()
273 {
274 #if DEBUG
275 log (LOG_BABBLE) << "Beginning of a recommends statement" << endLog;
276 dumpAndList (currentAndList);
277 #endif
278 currentSpec = NULL;
279 currentOrList = NULL; /* set by the build AndListNode */
280 currentAndList = cbpv.recommends();
281 }
282
283 void
284 IniDBBuilderPackage::buildBeginSuggests ()
285 {
286 #if DEBUG
287 log (LOG_BABBLE) << "Beginning of a suggests statement" << endLog;
288 dumpAndList (currentAndList);
289 #endif
290 currentSpec = NULL;
291 currentOrList = NULL; /* set by the build AndListNode */
292 currentAndList = cbpv.suggests();
293 }
294
295 void
296 IniDBBuilderPackage::buildBeginReplaces ()
297 {
298 #if DEBUG
299 log (LOG_BABBLE) << "Beginning of a replaces statement" << endLog;
300 dumpAndList (currentAndList);
301 #endif
302 currentSpec = NULL;
303 currentOrList = NULL; /* set by the build AndListNode */
304 currentAndList = cbpv.replaces();
305 }
306
307 void
308 IniDBBuilderPackage::buildBeginConflicts ()
309 {
310 #if DEBUG
311 log (LOG_BABBLE) << "Beginning of a conflicts statement" << endLog;
312 dumpAndList (currentAndList);
313 #endif
314 currentSpec = NULL;
315 currentOrList = NULL; /* set by the build AndListNode */
316 currentAndList = cbpv.conflicts();
317 }
318
319 void
320 IniDBBuilderPackage::buildBeginProvides ()
321 {
322 #if DEBUG
323 log (LOG_BABBLE) << "Beginning of a provides statement" << endLog;
324 dumpAndList (currentAndList);
325 #endif
326 currentSpec = NULL;
327 currentOrList = NULL; /* set by the build AndListNode */
328 currentAndList = cbpv.provides();
329 }
330
331 void
332 IniDBBuilderPackage::buildBeginBuildDepends ()
333 {
334 #if DEBUG
335 log (LOG_BABBLE) << "Beginning of a Build-Depends statement" << endLog;
336 dumpAndList (currentAndList);
337 #endif
338 currentSpec = NULL;
339 currentOrList = NULL; /* set by the build AndListNode */
340 currentAndList = cspv.depends ();
341 }
342
343
344 void
345 IniDBBuilderPackage::buildBeginBinary ()
346 {
347 #if DEBUG
348 log (LOG_BABBLE) << "Beginning of a Binary statement" << endLog;
349 dumpAndList (currentAndList);
350 #endif
351 currentSpec = NULL;
352 currentOrList = NULL; /* set by the build AndListNode */
353 currentAndList = cspv.binaries ();
354 }
355
356 void
357 IniDBBuilderPackage::buildDescription (String const &descline)
358 {
359 if (cbpv)
360 {
361 cbpv.set_ldesc(cbpv.LDesc() + descline + "\n");
362 #if DEBUG
363 log (LOG_BABBLE) << "Description for " << cp->name << ": \"" <<
364 descline << "\"." << endLog;
365 #endif
366 }
367 else
368 _feedback.warning ((String ("Attempt to set description for package")
369 + cp->name
370 + "before creation of a version.").cstr_oneuse());
371 }
372
373 void
374 IniDBBuilderPackage::buildSourceName (String const &name)
375 {
376 if (cbpv)
377 {
378 cbpv.setSourcePackageSpecification (PackageSpecification (name));
379 #if DEBUG
380 log (LOG_BABBLE) << "\"" << cpv->sourcePackageSpecification() <<
381 "\" is the source package for " << cp->name << "." << endLog;
382 #endif
383 }
384 else
385 _feedback.warning ((String ("Attempt to set source for package")
386 + cp->name
387 + "before creation of a version.").cstr_oneuse());
388 }
389
390 void
391 IniDBBuilderPackage::buildSourceNameVersion (String const &version)
392 {
393 if (cbpv)
394 {
395 cbpv.sourcePackageSpecification().setOperator (PackageSpecification::Equals);
396 cbpv.sourcePackageSpecification().setVersion (version);
397 #if DEBUG
398 log (LOG_BABBLE) << "The source version needed for " << cp->name <<
399 " is " << version << "." << endLog;
400 #endif
401 }
402 else
403 _feedback.warning ((String ("Attempt to set source version for package")
404 + cp->name
405 + "before creation of a version.").cstr_oneuse());
406 }
407
408 void
409 IniDBBuilderPackage::buildPackageListAndNode ()
410 {
411 if (currentAndList)
412 {
413 #if DEBUG
414 log (LOG_BABBLE) << "New AND node for a package list" << endLog;
415 if (currentOrList)
416 {
417 ostream &os = log (LOG_BABBLE);
418 os << "Current OR list is :";
419 for (vector<PackageSpecification *>::const_iterator i= currentOrList->begin();
420 i != currentOrList->end(); ++i)
421 os << endl << **i;
422 os << endLog;
423 }
424 #endif
425 currentSpec = NULL;
426 currentOrList = new vector<PackageSpecification *>;
427 currentAndList->push_back (currentOrList);
428 }
429 else
430 _feedback.warning ((String ("Attempt to add And node when no AndList"
431 " present for package ")
432 + cp->name).cstr_oneuse());
433 }
434
435 void
436 IniDBBuilderPackage::buildPackageListOrNode (String const &packageName)
437 {
438 if (currentOrList)
439 {
440 currentSpec = new PackageSpecification (packageName);
441 currentOrList->push_back (currentSpec);
442 #if DEBUG
443 log (LOG_BABBLE) << "New OR node in a package list refers to \"" <<
444 *currentSpec << "\"." << endLog;
445 #endif
446 }
447 else
448 _feedback.warning ((String ("Attempt to set specification for package ")
449 + cp->name
450 + " before creation of a version.").cstr_oneuse());
451 }
452
453 void
454 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators const &_operator)
455 {
456 if (currentSpec)
457 {
458 currentSpec->setOperator (_operator);
459 #if DEBUG
460 log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
461 endLog;
462 #endif
463 }
464 else
465 _feedback.warning ((String ("Attempt to set an operator for package ")
466 + cp->name
467 + " with no current specification.").cstr_oneuse());
468 }
469
470
471 void
472 IniDBBuilderPackage::buildPackageListOperatorVersion (String const &aVersion)
473 {
474 if (currentSpec)
475 {
476 currentSpec->setVersion (aVersion);
477 #if DEBUG
478 log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
479 endLog;
480 #endif
481 }
482 else
483 _feedback.warning ((String ("Attempt to set an operator version for package ")
484 + cp->name
485 + " with no current specification.").cstr_oneuse());
486 }
487
488 /* privates */
489
490 void
491 IniDBBuilderPackage::add_correct_version()
492 {
493 int merged = 0;
494 for (set<packageversion>::iterator n = cp->versions.begin();
495 !merged && n != cp->versions.end(); ++n)
496 if (*n == cbpv )
497 {
498 packageversion ver = *n;
499 /* ASSUMPTIONS:
500 categories and requires are consistent for the same version across
501 all mirrors
502 */
503 /* Copy the binary mirror across if this site claims to have an install */
504 if (cbpv.source()->sites.size() )
505 ver.source()->sites.push_back(site (cbpv.source()->sites.begin()->key));
506 /* Copy the descriptions across */
507 if (cbpv.SDesc ().size() && !n->SDesc ().size())
508 ver.set_sdesc (cbpv.SDesc ());
509 if (cbpv.LDesc ().size() && !n->LDesc ().size())
510 ver.set_ldesc (cbpv.LDesc ());
511 if (cbpv.depends()->size() && !ver.depends ()->size())
512 *ver.depends() = *cbpv.depends();
513 /* TODO: other package lists */
514 /* Prevent dangling references */
515 currentOrList = NULL;
516 currentAndList = NULL;
517 currentSpec = NULL;
518 cbpv = *n;
519 merged = 1;
520 }
521 if (!merged)
522 cp->add_version (cbpv);
523 /* trust setting */
524 switch (trust)
525 {
526 case TRUST_CURR:
527 if (cp->currtimestamp < timestamp)
528 {
529 cp->currtimestamp = timestamp;
530 cp->curr = cbpv;
531 }
532 break;
533 case TRUST_PREV:
534 if (cp->prevtimestamp < timestamp)
535 {
536 cp->prevtimestamp = timestamp;
537 cp->prev = cbpv;
538 }
539 break;
540 case TRUST_TEST:
541 if (cp->exptimestamp < timestamp)
542 {
543 cp->exptimestamp = timestamp;
544 cp->exp = cbpv;
545 }
546 break;
547 }
548 }
549
550 void
551 IniDBBuilderPackage::process_src (packagesource &src, String const &path)
552 {
553 if (!src.Canonical())
554 src.set_canonical (path.cstr_oneuse());
555 src.sites.push_back(site(parse_mirror));
556
557 if (!cbpv.Canonical_version ().size())
558 {
559 fileparse f;
560 if (parse_filename (path, f))
561 {
562 cbpv.setCanonicalVersion (f.ver);
563 add_correct_version ();
564 }
565 }
566 }
567
568 void
569 IniDBBuilderPackage::setSourceSize (packagesource &src, String const &size)
570 {
571 if (!src.size)
572 src.size = atoi(size.cstr_oneuse());
573 }
This page took 0.100601 seconds and 5 git commands to generate.