]> cygwin.com Git - cygwin-apps/setup.git/blame - IniDBBuilderPackage.cc
2002-07-09 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
237void
238IniDBBuilderPackage::buildArchitecture (String const &arch)
239{
240 cp->architecture = arch;
241#if DEBUG
242 log (LOG_BABBLE) << "Package " << cp->name << " is for " << arch << " architectures." << endLog;
243#endif
244}
245
246void
247IniDBBuilderPackage::buildInstallSize (String const &size)
248{
3c196821 249 setSourceSize (*cbpv.source(), size);
aa1e3b4d
RC
250}
251
252void
253IniDBBuilderPackage::buildInstallMD5 (unsigned char const * md5)
254{
3c196821
RC
255 if (md5 && !cbpv.source()->md5.isSet())
256 cbpv.source()->md5.set(md5);
aa1e3b4d
RC
257}
258
259void
260IniDBBuilderPackage::buildSourceMD5 (unsigned char const * md5)
261{
3c196821
RC
262 if (md5 && !cspv.source()->md5.isSet())
263 cspv.source()->md5.set(md5);
aa1e3b4d
RC
264}
265
266void
267IniDBBuilderPackage::buildBeginRecommends ()
268{
269#if DEBUG
270 log (LOG_BABBLE) << "Beginning of a recommends statement" << endLog;
271 dumpAndList (currentAndList);
272#endif
273 currentSpec = NULL;
274 currentOrList = NULL; /* set by the build AndListNode */
3c196821 275 currentAndList = cbpv.recommends();
aa1e3b4d
RC
276}
277
278void
279IniDBBuilderPackage::buildBeginSuggests ()
280{
281#if DEBUG
282 log (LOG_BABBLE) << "Beginning of a suggests statement" << endLog;
283 dumpAndList (currentAndList);
284#endif
285 currentSpec = NULL;
286 currentOrList = NULL; /* set by the build AndListNode */
3c196821 287 currentAndList = cbpv.suggests();
aa1e3b4d
RC
288}
289
290void
291IniDBBuilderPackage::buildBeginReplaces ()
292{
293#if DEBUG
294 log (LOG_BABBLE) << "Beginning of a replaces statement" << endLog;
295 dumpAndList (currentAndList);
296#endif
297 currentSpec = NULL;
298 currentOrList = NULL; /* set by the build AndListNode */
3c196821 299 currentAndList = cbpv.replaces();
aa1e3b4d
RC
300}
301
302void
303IniDBBuilderPackage::buildBeginConflicts ()
304{
305#if DEBUG
306 log (LOG_BABBLE) << "Beginning of a conflicts statement" << endLog;
307 dumpAndList (currentAndList);
308#endif
309 currentSpec = NULL;
310 currentOrList = NULL; /* set by the build AndListNode */
3c196821 311 currentAndList = cbpv.conflicts();
aa1e3b4d
RC
312}
313
314void
315IniDBBuilderPackage::buildBeginProvides ()
316{
317#if DEBUG
318 log (LOG_BABBLE) << "Beginning of a provides statement" << endLog;
319 dumpAndList (currentAndList);
320#endif
321 currentSpec = NULL;
322 currentOrList = NULL; /* set by the build AndListNode */
3c196821 323 currentAndList = cbpv.provides();
aa1e3b4d
RC
324}
325
326void
327IniDBBuilderPackage::buildDescription (String const &descline)
328{
3c196821 329 if (cbpv)
aa1e3b4d 330 {
3c196821 331 cbpv.set_ldesc(cbpv.LDesc() + descline + "\n");
aa1e3b4d
RC
332#if DEBUG
333 log (LOG_BABBLE) << "Description for " << cp->name << ": \"" <<
334 descline << "\"." << endLog;
335#endif
336 }
337 else
338 _feedback.warning ((String ("Attempt to set description for package")
339 + cp->name
340 + "before creation of a version.").cstr_oneuse());
341}
342
343void
344IniDBBuilderPackage::buildSourceName (String const &name)
345{
3c196821 346 if (cbpv)
aa1e3b4d 347 {
3c196821 348 cbpv.setSourcePackageSpecification (PackageSpecification (name));
aa1e3b4d 349#if DEBUG
3c196821 350 log (LOG_BABBLE) << "\"" << cpv->sourcePackageSpecification() <<
aa1e3b4d
RC
351 "\" is the source package for " << cp->name << "." << endLog;
352#endif
353 }
354 else
355 _feedback.warning ((String ("Attempt to set source for package")
356 + cp->name
357 + "before creation of a version.").cstr_oneuse());
358}
359
360void
361IniDBBuilderPackage::buildSourceNameVersion (String const &version)
362{
3c196821 363 if (cbpv)
aa1e3b4d 364 {
3c196821
RC
365 cbpv.sourcePackageSpecification().setOperator (PackageSpecification::Equals);
366 cbpv.sourcePackageSpecification().setVersion (version);
aa1e3b4d
RC
367#if DEBUG
368 log (LOG_BABBLE) << "The source version needed for " << cp->name <<
369 " is " << version << "." << endLog;
370#endif
371 }
372 else
373 _feedback.warning ((String ("Attempt to set source version for package")
374 + cp->name
375 + "before creation of a version.").cstr_oneuse());
376}
377
378void
379IniDBBuilderPackage::buildPackageListAndNode ()
380{
381 if (currentAndList)
382 {
383#if DEBUG
384 log (LOG_BABBLE) << "New AND node for a package list" << endLog;
385 if (currentOrList)
386 {
387 ostream &os = log (LOG_BABBLE);
388 os << "Current OR list is :";
389 for (vector<PackageSpecification *>::const_iterator i= currentOrList->begin();
390 i != currentOrList->end(); ++i)
391 os << endl << **i;
392 os << endLog;
393 }
394#endif
395 currentSpec = NULL;
396 currentOrList = new vector<PackageSpecification *>;
397 currentAndList->push_back (currentOrList);
398 }
399 else
400 _feedback.warning ((String ("Attempt to add And node when no AndList"
401 " present for package ")
402 + cp->name).cstr_oneuse());
403}
404
405void
406IniDBBuilderPackage::buildPackageListOrNode (String const &packageName)
407{
408 if (currentOrList)
409 {
410 currentSpec = new PackageSpecification (packageName);
411 currentOrList->push_back (currentSpec);
412#if DEBUG
413 log (LOG_BABBLE) << "New OR node in a package list refers to \"" <<
414 *currentSpec << "\"." << endLog;
415#endif
416 }
417 else
418 _feedback.warning ((String ("Attempt to set specification for package ")
419 + cp->name
420 + " before creation of a version.").cstr_oneuse());
421}
422
423void
424IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators const &_operator)
425{
426 if (currentSpec)
427 {
428 currentSpec->setOperator (_operator);
429#if DEBUG
430 log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
431 endLog;
432#endif
433 }
434 else
435 _feedback.warning ((String ("Attempt to set an operator for package ")
436 + cp->name
437 + " with no current specification.").cstr_oneuse());
438}
439
440
441void
442IniDBBuilderPackage::buildPackageListOperatorVersion (String const &aVersion)
443{
444 if (currentSpec)
445 {
446 currentSpec->setVersion (aVersion);
447#if DEBUG
448 log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
449 endLog;
450#endif
451 }
452 else
453 _feedback.warning ((String ("Attempt to set an operator version for package ")
454 + cp->name
455 + " with no current specification.").cstr_oneuse());
456}
457
458/* privates */
459
076654e7
RC
460void
461IniDBBuilderPackage::add_correct_version()
462{
463 int merged = 0;
3c196821
RC
464 for (set<packageversion>::iterator n = cp->versions.begin();
465 !merged && n != cp->versions.end(); ++n)
466 if (*n == cbpv )
076654e7 467 {
3c196821 468 packageversion ver = *n;
076654e7
RC
469 /* ASSUMPTIONS:
470 categories and requires are consistent for the same version across
471 all mirrors
472 */
473 /* Copy the binary mirror across if this site claims to have an install */
3f34f364
RC
474 if (cbpv.source()->sites.size() )
475 ver.source()->sites.push_back(site (cbpv.source()->sites.begin()->key));
076654e7 476 /* Copy the descriptions across */
3c196821
RC
477 if (cbpv.SDesc ().size() && !n->SDesc ().size())
478 ver.set_sdesc (cbpv.SDesc ());
479 if (cbpv.LDesc ().size() && !n->LDesc ().size())
480 ver.set_ldesc (cbpv.LDesc ());
7f2b9277
RC
481 if (cbpv.depends()->size() && !ver.depends ()->size())
482 *ver.depends() = *cbpv.depends();
483 /* TODO: other package lists */
484 /* Prevent dangling references */
485 currentOrList = NULL;
486 currentAndList = NULL;
487 currentSpec = NULL;
3c196821 488 cbpv = *n;
076654e7
RC
489 merged = 1;
490 }
7f2b9277 491 if (!merged)
3c196821 492 cp->add_version (cbpv);
076654e7
RC
493 /* trust setting */
494 switch (trust)
495 {
496 case TRUST_CURR:
497 if (cp->currtimestamp < timestamp)
498 {
499 cp->currtimestamp = timestamp;
3c196821 500 cp->curr = cbpv;
076654e7
RC
501 }
502 break;
503 case TRUST_PREV:
504 if (cp->prevtimestamp < timestamp)
505 {
506 cp->prevtimestamp = timestamp;
3c196821 507 cp->prev = cbpv;
076654e7
RC
508 }
509 break;
510 case TRUST_TEST:
511 if (cp->exptimestamp < timestamp)
512 {
513 cp->exptimestamp = timestamp;
3c196821 514 cp->exp = cbpv;
076654e7
RC
515 }
516 break;
517 }
518}
519
520void
aa1e3b4d 521IniDBBuilderPackage::process_src (packagesource &src, String const &path)
076654e7 522{
3c196821
RC
523 if (!src.Canonical())
524 src.set_canonical (path.cstr_oneuse());
3f34f364 525 src.sites.push_back(site(parse_mirror));
3c196821
RC
526
527 if (!cbpv.Canonical_version ().size())
076654e7
RC
528 {
529 fileparse f;
530 if (parse_filename (path, f))
531 {
3c196821 532 cbpv.setCanonicalVersion (f.ver);
076654e7
RC
533 add_correct_version ();
534 }
535 }
076654e7 536}
aa1e3b4d
RC
537
538void
539IniDBBuilderPackage::setSourceSize (packagesource &src, String const &size)
540{
541 if (!src.size)
542 src.size = atoi(size.cstr_oneuse());
543}
This page took 0.081024 seconds and 5 git commands to generate.