Translated using Weblate (Slovak)
[cygwin-setup.git] / IniDBBuilderPackage.cc
blob039404ba56419c936e3ee7369d0d06f41f0ceffd
1 /*
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
10 * http://www.gnu.org/
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"
25 #include "ini.h"
26 // for strtoul
27 #include <string.h>
28 #include "LogSingleton.h"
29 #include "PackageSpecification.h"
30 #include <algorithm>
32 IniDBBuilderPackage::IniDBBuilderPackage (IniParseFeedback const &aFeedback) :
33 currentSpec (0), _feedback (aFeedback), minimum_version_checked(FALSE) {}
35 IniDBBuilderPackage::~IniDBBuilderPackage()
37 process();
38 packagedb db;
39 db.solver.internalize();
42 void
43 IniDBBuilderPackage::buildTimestamp (const std::string& time)
45 timestamp = strtoul (time.c_str(), 0, 0);
48 void
49 IniDBBuilderPackage::buildVersion (const std::string& aVersion)
51 version = 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
57 to warn as well. */
58 if (minimum_version_checked)
59 return;
61 if (version.size())
63 if (version_compare(setup_version, version) < 0)
65 char old_vers[256];
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);
77 const std::string
78 IniDBBuilderPackage::buildMinimumVersion (const std::string& minimum)
80 minimum_version_checked = TRUE;
81 if (version_compare(setup_version, minimum) < 0)
83 char min_vers[256];
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",
87 minimum.c_str(),
88 is_64bit ? "x86_64" : "x86");
89 return min_vers;
91 return "";
94 void
95 IniDBBuilderPackage::buildPackage (const std::string& _name)
97 process();
99 /* Reset for next package */
100 name = _name;
101 message_id = "";
102 message_string = "";
103 categories.clear();
104 replace_versions.clear();
106 cbpv.reponame = release;
107 cbpv.version = "";
108 cbpv.vendor = release;
109 cbpv.sdesc = "";
110 cbpv.ldesc = "";
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();
121 currentSpec = NULL;
122 currentNodeList = NULL;
123 dependsNodeList = PackageDepends();
124 obsoletesNodeList = PackageDepends();
125 providesNodeList = PackageDepends();
126 conflictsNodeList = PackageDepends();
127 #if DEBUG
128 Log (LOG_BABBLE) << "Created package " << name << endLog;
129 #endif
132 void
133 IniDBBuilderPackage::buildPackageVersion (const std::string& version)
135 cbpv.version = version;
138 void
139 IniDBBuilderPackage::buildPackageSDesc (const std::string& theDesc)
141 cbpv.sdesc = theDesc;
144 void
145 IniDBBuilderPackage::buildPackageLDesc (const std::string& theDesc)
147 cbpv.ldesc = theDesc;
150 void
151 IniDBBuilderPackage::buildPackageInstall (const std::string& path,
152 const std::string& size,
153 char *hash,
154 hashType type)
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));
161 switch (type) {
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;
168 break;
170 case hashType::md5:
171 if (hash && !cbpv.archive.md5.isSet())
172 cbpv.archive.md5.set((unsigned char *)hash);
173 break;
175 case hashType::none:
176 break;
180 const std::string src_suffix = "-src";
182 void
183 IniDBBuilderPackage::buildPackageSource (const std::string& path,
184 const std::string& size,
185 char *hash,
186 hashType type)
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
190 package.
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));
210 switch (type) {
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;
217 break;
219 case hashType::md5:
220 if (hash && !cspv.archive.md5.isSet())
221 cspv.archive.md5.set((unsigned char *)hash);
222 break;
224 case hashType::none:
225 break;
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))
234 source_name = name;
235 else
236 source_name = name + src_suffix;
238 packagedb db;
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;
246 void
247 IniDBBuilderPackage::buildPackageTrust (trusts newtrust)
249 process();
250 cbpv.stability = newtrust;
253 void
254 IniDBBuilderPackage::buildPackageCategory (const std::string& name)
256 categories.insert(name);
259 void
260 IniDBBuilderPackage::buildBeginDepends ()
262 #if DEBUG
263 Log (LOG_BABBLE) << "Beginning of a depends statement " << endLog;
264 #endif
265 currentSpec = NULL;
266 dependsNodeList = PackageDepends();
267 currentNodeList = &dependsNodeList;
268 cbpv.requires = &dependsNodeList;
271 void
272 IniDBBuilderPackage::buildBeginBuildDepends ()
274 #if DEBUG
275 Log (LOG_BABBLE) << "Beginning of a Build-Depends statement" << endLog;
276 #endif
277 currentSpec = NULL;
278 currentNodeList = NULL;
279 /* there is currently nowhere to store Build-Depends information */
282 void
283 IniDBBuilderPackage::buildBeginObsoletes ()
285 #if DEBUG
286 Log (LOG_BABBLE) << "Beginning of an obsoletes statement" << endLog;
287 #endif
288 currentSpec = NULL;
289 obsoletesNodeList = PackageDepends();
290 currentNodeList = &obsoletesNodeList;
291 cbpv.obsoletes = &obsoletesNodeList;
294 void
295 IniDBBuilderPackage::buildBeginProvides ()
297 #if DEBUG
298 Log (LOG_BABBLE) << "Beginning of a provides statement" << endLog;
299 #endif
300 currentSpec = NULL;
301 providesNodeList = PackageDepends();
302 currentNodeList = &providesNodeList;
303 cbpv.provides = &providesNodeList;
306 void
307 IniDBBuilderPackage::buildBeginConflicts ()
309 #if DEBUG
310 Log (LOG_BABBLE) << "Beginning of a conflicts statement" << endLog;
311 #endif
312 currentSpec = NULL;
313 conflictsNodeList = PackageDepends();
314 currentNodeList = &conflictsNodeList;
315 cbpv.conflicts = &conflictsNodeList;
318 void
319 IniDBBuilderPackage::buildSourceName (const std::string& _name)
321 // When there is a Source: line, that names a real source package
322 packagedb db;
323 cbpv.spkg = PackageSpecification(_name);
324 cbpv.spkg_id = db.findSourceVersion (PackageSpecification(_name, cbpv.version));
325 #if DEBUG
326 Log (LOG_BABBLE) << "\"" << _name << "\" is the source package for " << name << "." << endLog;
327 #endif
330 void
331 IniDBBuilderPackage::buildSourceNameVersion (const std::string& version)
333 // XXX: should be stored as sourceevr
336 void
337 IniDBBuilderPackage::buildPackageListNode (const std::string & name)
339 #if DEBUG
340 Log (LOG_BABBLE) << "New node '" << name << "' for package list" << endLog;
341 #endif
343 std::string actual_name = name;
344 if (name == "_self-destruct")
345 actual_name = "libsolv-self-destruct-pkg()";
347 currentSpec = new PackageSpecification (actual_name);
348 if (currentNodeList)
349 currentNodeList->push_back (currentSpec);
352 void
353 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators const &_operator)
355 if (currentSpec)
357 currentSpec->setOperator (_operator);
358 #if DEBUG
359 Log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
360 endLog;
361 #endif
365 void
366 IniDBBuilderPackage::buildPackageListOperatorVersion (const std::string& aVersion)
368 if (currentSpec)
370 currentSpec->setVersion (aVersion);
371 #if DEBUG
372 Log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
373 endLog;
374 #endif
378 void
379 IniDBBuilderPackage::buildMessage (const std::string& _message_id, const std::string& _message_string)
381 message_id = _message_id;
382 message_string = _message_string;
385 void
386 IniDBBuilderPackage::buildPackageReplaceVersionsList (const std::string& version)
388 replace_versions.insert(version);
391 /* privates */
392 void
393 IniDBBuilderPackage::process ()
395 if (!name.size())
396 return;
398 if (cbpv.version.empty())
399 return;
401 // no install: line, no package
402 if (!cbpv.archive.Canonical())
403 return;
405 #if DEBUG
406 Log (LOG_BABBLE) << "Finished with package " << name << endLog;
407 Log (LOG_BABBLE) << "Version " << cbpv.version << endLog;
408 #endif
410 /* Transfer the accumulated package information to packagedb */
411 packagedb db;
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
424 cbpv.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();