Regenerate Japanese resources
[cygwin-setup.git] / IniDBBuilderPackage.cc
blob11edcd6657d2511d8afe7d07d768174273f7a859
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 static std::string
49 setup_dl_url()
51 return "https://cygwin.com/setup-" + machine_name(WindowsProcessMachine()) +".exe";
54 void
55 IniDBBuilderPackage::buildVersion (const std::string& aVersion)
57 version = aVersion;
59 /* We shouldn't need to warn about potential setup.ini parse problems if we
60 exceed the version in setup-minimum-version: (we will still advise about a
61 possible setup upgrade in do_ini_thread()). If we don't exceed
62 setup-minimum-version:, we've already encountered a fatal error, so no need
63 to warn as well. */
64 if (minimum_version_checked)
65 return;
67 if (version.size())
69 if (version_compare(setup_version, version) < 0)
71 char old_vers[256];
72 snprintf (old_vers, sizeof old_vers,
73 "A newer version of setup is available. "
74 "If you have any trouble installing, please download the latest "
75 "version from %s", setup_dl_url().c_str());
76 _feedback.warning(old_vers);
81 const std::string
82 IniDBBuilderPackage::buildMinimumVersion (const std::string& minimum)
84 minimum_version_checked = TRUE;
85 if (version_compare(setup_version, minimum) < 0)
87 char min_vers[256];
88 snprintf (min_vers, sizeof(min_vers),
89 "At least version %s of setup is required.\n"
90 "Please download a newer version from %s",
91 minimum.c_str(), setup_dl_url().c_str());
92 return min_vers;
94 return "";
97 void
98 IniDBBuilderPackage::buildPackage (const std::string& _name)
100 process();
102 /* Reset for next package */
103 name = _name;
104 message_id = "";
105 message_string = "";
106 categories.clear();
107 replace_versions.clear();
109 cbpv.reponame = release;
110 cbpv.version = "";
111 cbpv.vendor = release;
112 cbpv.sdesc = "";
113 cbpv.ldesc = "";
114 cbpv.stability = TRUST_CURR;
115 cbpv.type = package_binary;
116 cbpv.spkg = PackageSpecification();
117 cbpv.spkg_id = packageversion();
118 cbpv.requires = NULL;
119 cbpv.obsoletes = NULL;
120 cbpv.provides = NULL;
121 cbpv.conflicts = NULL;
122 cbpv.archive = packagesource();
124 currentSpec = NULL;
125 currentNodeList = NULL;
126 dependsNodeList = PackageDepends();
127 obsoletesNodeList = PackageDepends();
128 providesNodeList = PackageDepends();
129 conflictsNodeList = PackageDepends();
130 #if DEBUG
131 Log (LOG_BABBLE) << "Created package " << name << endLog;
132 #endif
135 void
136 IniDBBuilderPackage::buildPackageVersion (const std::string& version)
138 cbpv.version = version;
141 void
142 IniDBBuilderPackage::buildPackageSDesc (const std::string& theDesc)
144 cbpv.sdesc = theDesc;
147 void
148 IniDBBuilderPackage::buildPackageLDesc (const std::string& theDesc)
150 cbpv.ldesc = theDesc;
153 void
154 IniDBBuilderPackage::buildPackageInstall (const std::string& path,
155 const std::string& size,
156 char *hash,
157 hashType type)
159 // set archive path, size, mirror, hash
160 cbpv.archive.set_canonical(path.c_str());
161 cbpv.archive.size = atoi(size.c_str());
162 cbpv.archive.sites.push_back(site(parse_mirror));
164 switch (type) {
165 case hashType::sha512:
166 if (hash && !cbpv.archive.sha512_isSet)
168 memcpy (cbpv.archive.sha512sum, hash, sizeof(cbpv.archive.sha512sum));
169 cbpv.archive.sha512_isSet = true;
171 break;
173 case hashType::md5:
174 if (hash && !cbpv.archive.md5.isSet())
175 cbpv.archive.md5.set((unsigned char *)hash);
176 break;
178 case hashType::none:
179 break;
183 const std::string src_suffix = "-src";
185 void
186 IniDBBuilderPackage::buildPackageSource (const std::string& path,
187 const std::string& size,
188 char *hash,
189 hashType type)
191 /* When there is a source: line along with an install: line, we invent a
192 package to contain the source, and make it the source package for this
193 package.
195 When there's just a source: line, this is really a source package, which
196 will be referred to by a Source: line in other package(s).
199 /* create a source package version */
200 SolverPool::addPackageData cspv = cbpv;
201 cspv.type = package_source;
202 cspv.requires = NULL;
203 cspv.obsoletes = NULL;
204 cspv.provides = NULL;
205 cspv.conflicts = NULL;
207 /* set archive path, size, mirror, hash */
208 cspv.archive = packagesource();
209 cspv.archive.set_canonical(path.c_str());
210 cspv.archive.size = atoi(size.c_str());
211 cspv.archive.sites.push_back(site(parse_mirror));
213 switch (type) {
214 case hashType::sha512:
215 if (hash && !cspv.archive.sha512_isSet)
217 memcpy (cspv.archive.sha512sum, hash, sizeof(cspv.archive.sha512sum));
218 cspv.archive.sha512_isSet = true;
220 break;
222 case hashType::md5:
223 if (hash && !cspv.archive.md5.isSet())
224 cspv.archive.md5.set((unsigned char *)hash);
225 break;
227 case hashType::none:
228 break;
231 /* We make the source package name by appending '-src', unless it's already
232 there. This handles both cases above (assuming source package don't have
233 any install: lines, which should be true!) */
234 std::string source_name;
235 int pos = name.size() - src_suffix.size();
236 if ((pos > 0) && (name.compare(pos, src_suffix.size(), src_suffix) == 0))
237 source_name = name;
238 else
239 source_name = name + src_suffix;
241 packagedb db;
242 packageversion spkg_id = db.addSource (source_name, cspv);
244 /* create relationship between binary and source packageversions */
245 cbpv.spkg = PackageSpecification(source_name);
246 cbpv.spkg_id = spkg_id;
249 void
250 IniDBBuilderPackage::buildPackageTrust (trusts newtrust)
252 process();
253 cbpv.stability = newtrust;
256 void
257 IniDBBuilderPackage::buildPackageCategory (const std::string& name)
259 categories.insert(name);
262 void
263 IniDBBuilderPackage::buildBeginDepends ()
265 #if DEBUG
266 Log (LOG_BABBLE) << "Beginning of a depends statement " << endLog;
267 #endif
268 currentSpec = NULL;
269 dependsNodeList = PackageDepends();
270 currentNodeList = &dependsNodeList;
271 cbpv.requires = &dependsNodeList;
274 void
275 IniDBBuilderPackage::buildBeginBuildDepends ()
277 #if DEBUG
278 Log (LOG_BABBLE) << "Beginning of a Build-Depends statement" << endLog;
279 #endif
280 currentSpec = NULL;
281 currentNodeList = NULL;
282 /* there is currently nowhere to store Build-Depends information */
285 void
286 IniDBBuilderPackage::buildBeginObsoletes ()
288 #if DEBUG
289 Log (LOG_BABBLE) << "Beginning of an obsoletes statement" << endLog;
290 #endif
291 currentSpec = NULL;
292 obsoletesNodeList = PackageDepends();
293 currentNodeList = &obsoletesNodeList;
294 cbpv.obsoletes = &obsoletesNodeList;
297 void
298 IniDBBuilderPackage::buildBeginProvides ()
300 #if DEBUG
301 Log (LOG_BABBLE) << "Beginning of a provides statement" << endLog;
302 #endif
303 currentSpec = NULL;
304 providesNodeList = PackageDepends();
305 currentNodeList = &providesNodeList;
306 cbpv.provides = &providesNodeList;
309 void
310 IniDBBuilderPackage::buildBeginConflicts ()
312 #if DEBUG
313 Log (LOG_BABBLE) << "Beginning of a conflicts statement" << endLog;
314 #endif
315 currentSpec = NULL;
316 conflictsNodeList = PackageDepends();
317 currentNodeList = &conflictsNodeList;
318 cbpv.conflicts = &conflictsNodeList;
321 void
322 IniDBBuilderPackage::buildSourceName (const std::string& _name)
324 // When there is a Source: line, that names a real source package
325 packagedb db;
326 cbpv.spkg = PackageSpecification(_name);
327 cbpv.spkg_id = db.findSourceVersion (PackageSpecification(_name, cbpv.version));
328 #if DEBUG
329 Log (LOG_BABBLE) << "\"" << _name << "\" is the source package for " << name << "." << endLog;
330 #endif
333 void
334 IniDBBuilderPackage::buildSourceNameVersion (const std::string& version)
336 // XXX: should be stored as sourceevr
339 void
340 IniDBBuilderPackage::buildPackageListNode (const std::string & name)
342 #if DEBUG
343 Log (LOG_BABBLE) << "New node '" << name << "' for package list" << endLog;
344 #endif
346 std::string actual_name = name;
347 if (name == "_self-destruct")
348 actual_name = "libsolv-self-destruct-pkg()";
350 currentSpec = new PackageSpecification (actual_name);
351 if (currentNodeList)
352 currentNodeList->push_back (currentSpec);
355 void
356 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators const &_operator)
358 if (currentSpec)
360 currentSpec->setOperator (_operator);
361 #if DEBUG
362 Log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
363 endLog;
364 #endif
368 void
369 IniDBBuilderPackage::buildPackageListOperatorVersion (const std::string& aVersion)
371 if (currentSpec)
373 currentSpec->setVersion (aVersion);
374 #if DEBUG
375 Log (LOG_BABBLE) << "Current specification is " << *currentSpec << "." <<
376 endLog;
377 #endif
381 void
382 IniDBBuilderPackage::buildMessage (const std::string& _message_id, const std::string& _message_string)
384 message_id = _message_id;
385 message_string = _message_string;
388 void
389 IniDBBuilderPackage::buildPackageReplaceVersionsList (const std::string& version)
391 replace_versions.insert(version);
394 /* privates */
395 void
396 IniDBBuilderPackage::process ()
398 if (!name.size())
399 return;
401 if (cbpv.version.empty())
402 return;
404 // no install: line, no package
405 if (!cbpv.archive.Canonical())
406 return;
408 #if DEBUG
409 Log (LOG_BABBLE) << "Finished with package " << name << endLog;
410 Log (LOG_BABBLE) << "Version " << cbpv.version << endLog;
411 #endif
413 /* Transfer the accumulated package information to packagedb */
414 packagedb db;
415 packagemeta *pkg = db.addBinary (name, cbpv);
417 // For no good historical reason, some data lives in packagemeta rather than
418 // the packageversion
419 for (auto i = categories.begin(); i != categories.end(); i++)
421 pkg->add_category(*i);
423 pkg->set_message(message_id, message_string);
424 pkg->set_version_blacklist(replace_versions);
426 // Reset for next version
427 cbpv.version = "";
428 cbpv.type = package_binary;
429 cbpv.spkg = PackageSpecification();
430 cbpv.spkg_id = packageversion();
431 cbpv.archive = packagesource();
432 obsoletesNodeList = PackageDepends();
433 providesNodeList = PackageDepends();
434 conflictsNodeList = PackageDepends();