]> cygwin.com Git - cygwin-apps/setup.git/blame - IniDBBuilderPackage.cc
2002-07-13 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / IniDBBuilderPackage.cc
CommitLineData
076654e7
RC
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"
67829ce0 17#include "IniParseFeedback.h"
076654e7
RC
18#include "package_db.h"
19#include "package_meta.h"
20#include "package_version.h"
21#include "cygpackage.h"
22#include "filemanip.h"
67829ce0 23#include "version.h"
076654e7
RC
24// for strtoul
25#include <string.h>
aa1e3b4d
RC
26#include "LogSingleton.h"
27#include "PackageSpecification.h"
3c196821 28#include <algorithm>
076654e7 29
67829ce0 30IniDBBuilderPackage::IniDBBuilderPackage (IniParseFeedback const &aFeedback) :
3c196821 31cp (0), cbpv (), cspv (), currentSpec (0), currentOrList (0), currentAndList (0), trust (0), _feedback (aFeedback){}
67829ce0 32
076654e7
RC
33void
34IniDBBuilderPackage::buildTimestamp (String const &time)
35{
36 timestamp = strtoul (time.cstr_oneuse(), 0, 0);
37}
38
39void
40IniDBBuilderPackage::buildVersion (String const &aVersion)
41{
42 version = aVersion;
67829ce0
RC
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 }
076654e7
RC
51}
52
7f2b9277
RC
53void dumpAndList (vector<vector <PackageSpecification *> *> *currentAndList);
54
076654e7
RC
55void
56IniDBBuilderPackage::buildPackage (String const &name)
57{
7f2b9277
RC
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
076654e7 70 packagedb db;
cfae3b8d
RC
71 cp = db.findBinary (PackageSpecification(name));
72 if (!cp)
73 {
74 cp = new packagemeta (name);
75 db.packages.push_back (cp);
76 }
3c196821
RC
77 cbpv = cygpackage::createInstance (name);
78 cspv = packageversion ();
aa1e3b4d 79 currentSpec = NULL;
7f2b9277
RC
80 currentOrList = NULL;
81 currentAndList = NULL;
076654e7 82 trust = TRUST_CURR;
3c196821
RC
83#if DEBUG
84 log (LOG_BABBLE) << "Created package " << name << endLog;
85#endif
076654e7
RC
86}
87
88void
89IniDBBuilderPackage::buildPackageVersion (String const &version)
90{
3c196821 91 cbpv.setCanonicalVersion (version);
076654e7
RC
92 add_correct_version();
93}
94
95void
96IniDBBuilderPackage::buildPackageSDesc (String const &theDesc)
97{
3c196821 98 cbpv.set_sdesc(theDesc);
076654e7
RC
99}
100
101void
102IniDBBuilderPackage::buildPackageLDesc (String const &theDesc)
103{
3c196821 104 cbpv.set_ldesc(theDesc);
aa1e3b4d
RC
105#if DEBUG
106 _feedback.warning(theDesc.cstr_oneuse());
107#endif
076654e7
RC
108}
109
110void
aa1e3b4d 111IniDBBuilderPackage::buildPackageInstall (String const &path)
076654e7 112{
3c196821 113 process_src (*cbpv.source(), path);
076654e7 114}
3c196821 115
076654e7 116void
aa1e3b4d 117IniDBBuilderPackage::buildPackageSource (String const &path, String const &size)
076654e7 118{
3c196821
RC
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();
64cd7f94
RC
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);
3c196821
RC
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());
3f34f364 149 cspv.source()->sites.push_back(site(parse_mirror));
3c196821
RC
150
151 cbpv.setSourcePackageSpecification (PackageSpecification (cspv.Name()));
152
153 // process_src (*cspv.source(), path);
154 setSourceSize (*cspv.source(), size);
076654e7
RC
155}
156
157void
158IniDBBuilderPackage::buildPackageTrust (int newtrust)
159{
160 trust = newtrust;
161 if (newtrust != TRUST_UNKNOWN)
3c196821
RC
162 {
163 cbpv = cygpackage::createInstance (cp->name);
164 cspv = packageversion ();
165 }
076654e7
RC
166}
167
168void
169IniDBBuilderPackage::buildPackageCategory (String const &name)
170{
0cf68afd 171 cp->add_category (name);
076654e7
RC
172}
173
aa1e3b4d
RC
174void 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
191void
192IniDBBuilderPackage::buildBeginDepends ()
193{
194#if DEBUG
7f2b9277
RC
195 log (LOG_BABBLE) << "Beginning of a depends statement for " << cp->name
196 << endLog;
aa1e3b4d
RC
197 dumpAndList (currentAndList);
198#endif
199 currentSpec = NULL;
200 currentOrList = NULL; /* set by the build AndListNode */
3c196821 201 currentAndList = cbpv.depends();
aa1e3b4d
RC
202}
203
204void
205IniDBBuilderPackage::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 */
3c196821 213 currentAndList = cbpv.predepends();
aa1e3b4d
RC
214}
215
216void
217IniDBBuilderPackage::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
225void
226IniDBBuilderPackage::buildInstalledSize (String const &size)
227{
3c196821 228 cbpv.source()->setInstalledSize (atoi(size.cstr_oneuse()));
aa1e3b4d
RC
229#if DEBUG
230 log (LOG_BABBLE) << "Installed size for " << cp->name << " is " << cpv->bin.installedSize() << endLog;
231#endif
232}
233
234void
235IniDBBuilderPackage::buildMaintainer (String const &){}
236
b1ff53ed
RC
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 */
aa1e3b4d
RC
242void
243IniDBBuilderPackage::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
251void
252IniDBBuilderPackage::buildInstallSize (String const &size)
253{
3c196821 254 setSourceSize (*cbpv.source(), size);
aa1e3b4d
RC
255}
256
257void
258IniDBBuilderPackage::buildInstallMD5 (unsigned char const * md5)
259{
3c196821
RC
260 if (md5 && !cbpv.source()->md5.isSet())
261 cbpv.source()->md5.set(md5);
aa1e3b4d
RC
262}
263
264void
265IniDBBuilderPackage::buildSourceMD5 (unsigned char const * md5)
266{
3c196821
RC
267 if (md5 && !cspv.source()->md5.isSet())
268 cspv.source()->md5.set(md5);
aa1e3b4d
RC
269}
270
271void
272IniDBBuilderPackage::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 */
3c196821 280 currentAndList = cbpv.recommends();
aa1e3b4d
RC
281}
282
283void
284IniDBBuilderPackage::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 */
3c196821 292 currentAndList = cbpv.suggests();
aa1e3b4d
RC
293}
294
295void
296IniDBBuilderPackage::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 */
3c196821 304 currentAndList = cbpv.replaces();
aa1e3b4d
RC
305}
306
307void
308IniDBBuilderPackage::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 */
3c196821 316 currentAndList = cbpv.conflicts();
aa1e3b4d
RC
317}
318
319void
320IniDBBuilderPackage::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 */
3c196821 328 currentAndList = cbpv.provides();
aa1e3b4d
RC
329}
330
b1ff53ed
RC
331void
332IniDBBuilderPackage::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
344void
345IniDBBuilderPackage::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
aa1e3b4d
RC
356void
357IniDBBuilderPackage::buildDescription (String const &descline)
358{
3c196821 359 if (cbpv)
aa1e3b4d 360 {
3c196821 361 cbpv.set_ldesc(cbpv.LDesc() + descline + "\n");
aa1e3b4d
RC
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
373void
374IniDBBuilderPackage::buildSourceName (String const &name)
375{
3c196821 376 if (cbpv)
aa1e3b4d 377 {
3c196821 378 cbpv.setSourcePackageSpecification (PackageSpecification (name));
aa1e3b4d 379#if DEBUG
3c196821 380 log (LOG_BABBLE) << "\"" << cpv->sourcePackageSpecification() <<
aa1e3b4d
RC
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
390void
391IniDBBuilderPackage::buildSourceNameVersion (String const &version)
392{
3c196821 393 if (cbpv)
aa1e3b4d 394 {
3c196821
RC
395 cbpv.sourcePackageSpecification().setOperator (PackageSpecification::Equals);
396 cbpv.sourcePackageSpecification().setVersion (version);
aa1e3b4d
RC
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
408void
409IniDBBuilderPackage::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
435void
436IniDBBuilderPackage::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
453void
454IniDBBuilderPackage::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
471void
472IniDBBuilderPackage::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
076654e7
RC
490void
491IniDBBuilderPackage::add_correct_version()
492{
493 int merged = 0;
3c196821
RC
494 for (set<packageversion>::iterator n = cp->versions.begin();
495 !merged && n != cp->versions.end(); ++n)
496 if (*n == cbpv )
076654e7 497 {
3c196821 498 packageversion ver = *n;
076654e7
RC
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 */
3f34f364
RC
504 if (cbpv.source()->sites.size() )
505 ver.source()->sites.push_back(site (cbpv.source()->sites.begin()->key));
076654e7 506 /* Copy the descriptions across */
3c196821
RC
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 ());
7f2b9277
RC
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;
3c196821 518 cbpv = *n;
076654e7
RC
519 merged = 1;
520 }
7f2b9277 521 if (!merged)
3c196821 522 cp->add_version (cbpv);
076654e7
RC
523 /* trust setting */
524 switch (trust)
525 {
526 case TRUST_CURR:
527 if (cp->currtimestamp < timestamp)
528 {
529 cp->currtimestamp = timestamp;
3c196821 530 cp->curr = cbpv;
076654e7
RC
531 }
532 break;
533 case TRUST_PREV:
534 if (cp->prevtimestamp < timestamp)
535 {
536 cp->prevtimestamp = timestamp;
3c196821 537 cp->prev = cbpv;
076654e7
RC
538 }
539 break;
540 case TRUST_TEST:
541 if (cp->exptimestamp < timestamp)
542 {
543 cp->exptimestamp = timestamp;
3c196821 544 cp->exp = cbpv;
076654e7
RC
545 }
546 break;
547 }
548}
549
550void
aa1e3b4d 551IniDBBuilderPackage::process_src (packagesource &src, String const &path)
076654e7 552{
3c196821
RC
553 if (!src.Canonical())
554 src.set_canonical (path.cstr_oneuse());
3f34f364 555 src.sites.push_back(site(parse_mirror));
3c196821
RC
556
557 if (!cbpv.Canonical_version ().size())
076654e7
RC
558 {
559 fileparse f;
560 if (parse_filename (path, f))
561 {
3c196821 562 cbpv.setCanonicalVersion (f.ver);
076654e7
RC
563 add_correct_version ();
564 }
565 }
076654e7 566}
aa1e3b4d
RC
567
568void
569IniDBBuilderPackage::setSourceSize (packagesource &src, String const &size)
570{
571 if (!src.size)
572 src.size = atoi(size.cstr_oneuse());
573}
This page took 0.084267 seconds and 5 git commands to generate.