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