]> cygwin.com Git - cygwin-apps/setup.git/blame - IniDBBuilderPackage.cc
2002-07-08 Max Bowsher <maxb@ukf.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"
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
RC
70 packagedb db;
71 cp = &db.packages.registerbykey(name);
3c196821
RC
72 cbpv = cygpackage::createInstance (name);
73 cspv = packageversion ();
aa1e3b4d 74 currentSpec = NULL;
7f2b9277
RC
75 currentOrList = NULL;
76 currentAndList = NULL;
076654e7 77 trust = TRUST_CURR;
3c196821
RC
78#if DEBUG
79 log (LOG_BABBLE) << "Created package " << name << endLog;
80#endif
076654e7
RC
81}
82
83void
84IniDBBuilderPackage::buildPackageVersion (String const &version)
85{
3c196821 86 cbpv.setCanonicalVersion (version);
076654e7
RC
87 add_correct_version();
88}
89
90void
91IniDBBuilderPackage::buildPackageSDesc (String const &theDesc)
92{
3c196821 93 cbpv.set_sdesc(theDesc);
076654e7
RC
94}
95
96void
97IniDBBuilderPackage::buildPackageLDesc (String const &theDesc)
98{
3c196821 99 cbpv.set_ldesc(theDesc);
aa1e3b4d
RC
100#if DEBUG
101 _feedback.warning(theDesc.cstr_oneuse());
102#endif
076654e7
RC
103}
104
105void
aa1e3b4d 106IniDBBuilderPackage::buildPackageInstall (String const &path)
076654e7 107{
3c196821 108 process_src (*cbpv.source(), path);
076654e7 109}
3c196821 110
076654e7 111void
aa1e3b4d 112IniDBBuilderPackage::buildPackageSource (String const &path, String const &size)
076654e7 113{
3c196821
RC
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();
64cd7f94
RC
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);
3c196821
RC
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());
3f34f364 144 cspv.source()->sites.push_back(site(parse_mirror));
3c196821
RC
145
146 cbpv.setSourcePackageSpecification (PackageSpecification (cspv.Name()));
147
148 // process_src (*cspv.source(), path);
149 setSourceSize (*cspv.source(), size);
076654e7
RC
150}
151
152void
153IniDBBuilderPackage::buildPackageTrust (int newtrust)
154{
155 trust = newtrust;
156 if (newtrust != TRUST_UNKNOWN)
3c196821
RC
157 {
158 cbpv = cygpackage::createInstance (cp->name);
159 cspv = packageversion ();
160 }
076654e7
RC
161}
162
163void
164IniDBBuilderPackage::buildPackageCategory (String const &name)
165{
0cf68afd 166 cp->add_category (name);
076654e7
RC
167}
168
aa1e3b4d
RC
169void 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
186void
187IniDBBuilderPackage::buildBeginDepends ()
188{
189#if DEBUG
7f2b9277
RC
190 log (LOG_BABBLE) << "Beginning of a depends statement for " << cp->name
191 << endLog;
aa1e3b4d
RC
192 dumpAndList (currentAndList);
193#endif
194 currentSpec = NULL;
195 currentOrList = NULL; /* set by the build AndListNode */
3c196821 196 currentAndList = cbpv.depends();
aa1e3b4d
RC
197}
198
199void
200IniDBBuilderPackage::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 */
3c196821 208 currentAndList = cbpv.predepends();
aa1e3b4d
RC
209}
210
211void
212IniDBBuilderPackage::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
220void
221IniDBBuilderPackage::buildInstalledSize (String const &size)
222{
3c196821 223 cbpv.source()->setInstalledSize (atoi(size.cstr_oneuse()));
aa1e3b4d
RC
224#if DEBUG
225 log (LOG_BABBLE) << "Installed size for " << cp->name << " is " << cpv->bin.installedSize() << endLog;
226#endif
227}
228
229void
230IniDBBuilderPackage::buildMaintainer (String const &){}
231
232void
233IniDBBuilderPackage::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
241void
242IniDBBuilderPackage::buildInstallSize (String const &size)
243{
3c196821 244 setSourceSize (*cbpv.source(), size);
aa1e3b4d
RC
245}
246
247void
248IniDBBuilderPackage::buildInstallMD5 (unsigned char const * md5)
249{
3c196821
RC
250 if (md5 && !cbpv.source()->md5.isSet())
251 cbpv.source()->md5.set(md5);
aa1e3b4d
RC
252}
253
254void
255IniDBBuilderPackage::buildSourceMD5 (unsigned char const * md5)
256{
3c196821
RC
257 if (md5 && !cspv.source()->md5.isSet())
258 cspv.source()->md5.set(md5);
aa1e3b4d
RC
259}
260
261void
262IniDBBuilderPackage::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 */
3c196821 270 currentAndList = cbpv.recommends();
aa1e3b4d
RC
271}
272
273void
274IniDBBuilderPackage::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 */
3c196821 282 currentAndList = cbpv.suggests();
aa1e3b4d
RC
283}
284
285void
286IniDBBuilderPackage::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 */
3c196821 294 currentAndList = cbpv.replaces();
aa1e3b4d
RC
295}
296
297void
298IniDBBuilderPackage::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 */
3c196821 306 currentAndList = cbpv.conflicts();
aa1e3b4d
RC
307}
308
309void
310IniDBBuilderPackage::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 */
3c196821 318 currentAndList = cbpv.provides();
aa1e3b4d
RC
319}
320
321void
322IniDBBuilderPackage::buildDescription (String const &descline)
323{
3c196821 324 if (cbpv)
aa1e3b4d 325 {
3c196821 326 cbpv.set_ldesc(cbpv.LDesc() + descline + "\n");
aa1e3b4d
RC
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
338void
339IniDBBuilderPackage::buildSourceName (String const &name)
340{
3c196821 341 if (cbpv)
aa1e3b4d 342 {
3c196821 343 cbpv.setSourcePackageSpecification (PackageSpecification (name));
aa1e3b4d 344#if DEBUG
3c196821 345 log (LOG_BABBLE) << "\"" << cpv->sourcePackageSpecification() <<
aa1e3b4d
RC
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
355void
356IniDBBuilderPackage::buildSourceNameVersion (String const &version)
357{
3c196821 358 if (cbpv)
aa1e3b4d 359 {
3c196821
RC
360 cbpv.sourcePackageSpecification().setOperator (PackageSpecification::Equals);
361 cbpv.sourcePackageSpecification().setVersion (version);
aa1e3b4d
RC
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
373void
374IniDBBuilderPackage::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
400void
401IniDBBuilderPackage::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
418void
419IniDBBuilderPackage::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
436void
437IniDBBuilderPackage::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
076654e7
RC
455void
456IniDBBuilderPackage::add_correct_version()
457{
458 int merged = 0;
3c196821
RC
459 for (set<packageversion>::iterator n = cp->versions.begin();
460 !merged && n != cp->versions.end(); ++n)
461 if (*n == cbpv )
076654e7 462 {
3c196821 463 packageversion ver = *n;
076654e7
RC
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 */
3f34f364
RC
469 if (cbpv.source()->sites.size() )
470 ver.source()->sites.push_back(site (cbpv.source()->sites.begin()->key));
076654e7 471 /* Copy the descriptions across */
3c196821
RC
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 ());
7f2b9277
RC
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;
3c196821 483 cbpv = *n;
076654e7
RC
484 merged = 1;
485 }
7f2b9277 486 if (!merged)
3c196821 487 cp->add_version (cbpv);
076654e7
RC
488 /* trust setting */
489 switch (trust)
490 {
491 case TRUST_CURR:
492 if (cp->currtimestamp < timestamp)
493 {
494 cp->currtimestamp = timestamp;
3c196821 495 cp->curr = cbpv;
076654e7
RC
496 }
497 break;
498 case TRUST_PREV:
499 if (cp->prevtimestamp < timestamp)
500 {
501 cp->prevtimestamp = timestamp;
3c196821 502 cp->prev = cbpv;
076654e7
RC
503 }
504 break;
505 case TRUST_TEST:
506 if (cp->exptimestamp < timestamp)
507 {
508 cp->exptimestamp = timestamp;
3c196821 509 cp->exp = cbpv;
076654e7
RC
510 }
511 break;
512 }
513}
514
515void
aa1e3b4d 516IniDBBuilderPackage::process_src (packagesource &src, String const &path)
076654e7 517{
3c196821
RC
518 if (!src.Canonical())
519 src.set_canonical (path.cstr_oneuse());
3f34f364 520 src.sites.push_back(site(parse_mirror));
3c196821
RC
521
522 if (!cbpv.Canonical_version ().size())
076654e7
RC
523 {
524 fileparse f;
525 if (parse_filename (path, f))
526 {
3c196821 527 cbpv.setCanonicalVersion (f.ver);
076654e7
RC
528 add_correct_version ();
529 }
530 }
076654e7 531}
aa1e3b4d
RC
532
533void
534IniDBBuilderPackage::setSourceSize (packagesource &src, String const &size)
535{
536 if (!src.size)
537 src.size = atoi(size.cstr_oneuse());
538}
This page took 0.084846 seconds and 5 git commands to generate.