2 * Copyright (c) 2002, Robert Collins.
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.
9 * A copy of the GNU General Public License can be found at
12 * Written by Robert Collins <rbtcollins@hotmail.com>
16 #include "IniDBBuilderPackage.h"
18 #include "csu_util/version_compare.h"
20 #include "setup_version.h"
22 #include "IniParseFeedback.h"
23 #include "package_db.h"
24 #include "package_meta.h"
28 #include "LogSingleton.h"
29 #include "PackageSpecification.h"
32 IniDBBuilderPackage::IniDBBuilderPackage (IniParseFeedback
const &aFeedback
) :
33 currentSpec (0), _feedback (aFeedback
), minimum_version_checked(FALSE
) {}
35 IniDBBuilderPackage::~IniDBBuilderPackage()
39 db
.solver
.internalize();
43 IniDBBuilderPackage::buildTimestamp (const std::string
& time
)
45 timestamp
= strtoul (time
.c_str(), 0, 0);
49 IniDBBuilderPackage::buildVersion (const std::string
& aVersion
)
53 /* We shouldn't need to warn about potential setup.ini parse problems if we
54 exceed the version in setup-minimum-version: (we will still advise about a
55 possible setup upgrade in do_ini_thread()). If we don't exceed
56 setup-minimum-version:, we've already encountered a fatal error, so no need
58 if (minimum_version_checked
)
63 if (version_compare(setup_version
, version
) < 0)
66 snprintf (old_vers
, sizeof old_vers
,
67 "The current ini file is from a newer version of setup-%s.exe. "
68 "If you have any trouble installing, please download a fresh "
69 "version from https://cygwin.com/setup-%s.exe",
70 is_64bit
? "x86_64" : "x86",
71 is_64bit
? "x86_64" : "x86");
72 _feedback
.warning(old_vers
);
78 IniDBBuilderPackage::buildMinimumVersion (const std::string
& minimum
)
80 minimum_version_checked
= TRUE
;
81 if (version_compare(setup_version
, minimum
) < 0)
84 snprintf (min_vers
, sizeof(min_vers
),
85 "The current ini file requires at least version %s of setup.\n"
86 "Please download a newer version from https://cygwin.com/setup-%s.exe",
88 is_64bit
? "x86_64" : "x86");
95 IniDBBuilderPackage::buildPackage (const std::string
& _name
)
99 /* Reset for next package */
104 replace_versions
.clear();
106 cbpv
.reponame
= release
;
108 cbpv
.vendor
= release
;
111 cbpv
.stability
= TRUST_CURR
;
112 cbpv
.type
= package_binary
;
113 cbpv
.spkg
= PackageSpecification();
114 cbpv
.spkg_id
= packageversion();
115 cbpv
.requires
= NULL
;
116 cbpv
.obsoletes
= NULL
;
117 cbpv
.provides
= NULL
;
118 cbpv
.conflicts
= NULL
;
119 cbpv
.archive
= packagesource();
122 currentNodeList
= NULL
;
123 dependsNodeList
= PackageDepends();
124 obsoletesNodeList
= PackageDepends();
125 providesNodeList
= PackageDepends();
126 conflictsNodeList
= PackageDepends();
128 Log (LOG_BABBLE
) << "Created package " << name
<< endLog
;
133 IniDBBuilderPackage::buildPackageVersion (const std::string
& version
)
135 cbpv
.version
= version
;
139 IniDBBuilderPackage::buildPackageSDesc (const std::string
& theDesc
)
141 cbpv
.sdesc
= theDesc
;
145 IniDBBuilderPackage::buildPackageLDesc (const std::string
& theDesc
)
147 cbpv
.ldesc
= theDesc
;
151 IniDBBuilderPackage::buildPackageInstall (const std::string
& path
,
152 const std::string
& size
,
156 // set archive path, size, mirror, hash
157 cbpv
.archive
.set_canonical(path
.c_str());
158 cbpv
.archive
.size
= atoi(size
.c_str());
159 cbpv
.archive
.sites
.push_back(site(parse_mirror
));
162 case hashType::sha512
:
163 if (hash
&& !cbpv
.archive
.sha512_isSet
)
165 memcpy (cbpv
.archive
.sha512sum
, hash
, sizeof(cbpv
.archive
.sha512sum
));
166 cbpv
.archive
.sha512_isSet
= true;
171 if (hash
&& !cbpv
.archive
.md5
.isSet())
172 cbpv
.archive
.md5
.set((unsigned char *)hash
);
180 const std::string src_suffix
= "-src";
183 IniDBBuilderPackage::buildPackageSource (const std::string
& path
,
184 const std::string
& size
,
188 /* When there is a source: line along with an install: line, we invent a
189 package to contain the source, and make it the source package for this
192 When there's just a source: line, this is really a source package, which
193 will be referred to by a Source: line in other package(s).
196 /* create a source package version */
197 SolverPool::addPackageData cspv
= cbpv
;
198 cspv
.type
= package_source
;
199 cspv
.requires
= NULL
;
200 cspv
.obsoletes
= NULL
;
201 cspv
.provides
= NULL
;
202 cspv
.conflicts
= NULL
;
204 /* set archive path, size, mirror, hash */
205 cspv
.archive
= packagesource();
206 cspv
.archive
.set_canonical(path
.c_str());
207 cspv
.archive
.size
= atoi(size
.c_str());
208 cspv
.archive
.sites
.push_back(site(parse_mirror
));
211 case hashType::sha512
:
212 if (hash
&& !cspv
.archive
.sha512_isSet
)
214 memcpy (cspv
.archive
.sha512sum
, hash
, sizeof(cspv
.archive
.sha512sum
));
215 cspv
.archive
.sha512_isSet
= true;
220 if (hash
&& !cspv
.archive
.md5
.isSet())
221 cspv
.archive
.md5
.set((unsigned char *)hash
);
228 /* We make the source package name by appending '-src', unless it's already
229 there. This handles both cases above (assuming source package don't have
230 any install: lines, which should be true!) */
231 std::string source_name
;
232 int pos
= name
.size() - src_suffix
.size();
233 if ((pos
> 0) && (name
.compare(pos
, src_suffix
.size(), src_suffix
) == 0))
236 source_name
= name
+ src_suffix
;
239 packageversion spkg_id
= db
.addSource (source_name
, cspv
);
241 /* create relationship between binary and source packageversions */
242 cbpv
.spkg
= PackageSpecification(source_name
);
243 cbpv
.spkg_id
= spkg_id
;
247 IniDBBuilderPackage::buildPackageTrust (trusts newtrust
)
250 cbpv
.stability
= newtrust
;
254 IniDBBuilderPackage::buildPackageCategory (const std::string
& name
)
256 categories
.insert(name
);
260 IniDBBuilderPackage::buildBeginDepends ()
263 Log (LOG_BABBLE
) << "Beginning of a depends statement " << endLog
;
266 dependsNodeList
= PackageDepends();
267 currentNodeList
= &dependsNodeList
;
268 cbpv
.requires
= &dependsNodeList
;
272 IniDBBuilderPackage::buildBeginBuildDepends ()
275 Log (LOG_BABBLE
) << "Beginning of a Build-Depends statement" << endLog
;
278 currentNodeList
= NULL
;
279 /* there is currently nowhere to store Build-Depends information */
283 IniDBBuilderPackage::buildBeginObsoletes ()
286 Log (LOG_BABBLE
) << "Beginning of an obsoletes statement" << endLog
;
289 obsoletesNodeList
= PackageDepends();
290 currentNodeList
= &obsoletesNodeList
;
291 cbpv
.obsoletes
= &obsoletesNodeList
;
295 IniDBBuilderPackage::buildBeginProvides ()
298 Log (LOG_BABBLE
) << "Beginning of a provides statement" << endLog
;
301 providesNodeList
= PackageDepends();
302 currentNodeList
= &providesNodeList
;
303 cbpv
.provides
= &providesNodeList
;
307 IniDBBuilderPackage::buildBeginConflicts ()
310 Log (LOG_BABBLE
) << "Beginning of a conflicts statement" << endLog
;
313 conflictsNodeList
= PackageDepends();
314 currentNodeList
= &conflictsNodeList
;
315 cbpv
.conflicts
= &conflictsNodeList
;
319 IniDBBuilderPackage::buildSourceName (const std::string
& _name
)
321 // When there is a Source: line, that names a real source package
323 cbpv
.spkg
= PackageSpecification(_name
);
324 cbpv
.spkg_id
= db
.findSourceVersion (PackageSpecification(_name
, cbpv
.version
));
326 Log (LOG_BABBLE
) << "\"" << _name
<< "\" is the source package for " << name
<< "." << endLog
;
331 IniDBBuilderPackage::buildSourceNameVersion (const std::string
& version
)
333 // XXX: should be stored as sourceevr
337 IniDBBuilderPackage::buildPackageListNode (const std::string
& name
)
340 Log (LOG_BABBLE
) << "New node '" << name
<< "' for package list" << endLog
;
343 std::string actual_name
= name
;
344 if (name
== "_self-destruct")
345 actual_name
= "libsolv-self-destruct-pkg()";
347 currentSpec
= new PackageSpecification (actual_name
);
349 currentNodeList
->push_back (currentSpec
);
353 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators
const &_operator
)
357 currentSpec
->setOperator (_operator
);
359 Log (LOG_BABBLE
) << "Current specification is " << *currentSpec
<< "." <<
366 IniDBBuilderPackage::buildPackageListOperatorVersion (const std::string
& aVersion
)
370 currentSpec
->setVersion (aVersion
);
372 Log (LOG_BABBLE
) << "Current specification is " << *currentSpec
<< "." <<
379 IniDBBuilderPackage::buildMessage (const std::string
& _message_id
, const std::string
& _message_string
)
381 message_id
= _message_id
;
382 message_string
= _message_string
;
386 IniDBBuilderPackage::buildPackageReplaceVersionsList (const std::string
& version
)
388 replace_versions
.insert(version
);
393 IniDBBuilderPackage::process ()
398 if (cbpv
.version
.empty())
401 // no install: line, no package
402 if (!cbpv
.archive
.Canonical())
406 Log (LOG_BABBLE
) << "Finished with package " << name
<< endLog
;
407 Log (LOG_BABBLE
) << "Version " << cbpv
.version
<< endLog
;
410 /* Transfer the accumulated package information to packagedb */
412 packagemeta
*pkg
= db
.addBinary (name
, cbpv
);
414 // For no good historical reason, some data lives in packagemeta rather than
415 // the packageversion
416 for (auto i
= categories
.begin(); i
!= categories
.end(); i
++)
418 pkg
->add_category(*i
);
420 pkg
->set_message(message_id
, message_string
);
421 pkg
->set_version_blacklist(replace_versions
);
423 // Reset for next version
425 cbpv
.type
= package_binary
;
426 cbpv
.spkg
= PackageSpecification();
427 cbpv
.spkg_id
= packageversion();
428 cbpv
.archive
= packagesource();
429 obsoletesNodeList
= PackageDepends();
430 providesNodeList
= PackageDepends();
431 conflictsNodeList
= PackageDepends();