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