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);
51 return "https://cygwin.com/setup-" + machine_name(WindowsProcessMachine()) +".exe";
55 IniDBBuilderPackage::buildVersion (const std::string
& 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
64 if (minimum_version_checked
)
69 if (version_compare(setup_version
, version
) < 0)
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
);
82 IniDBBuilderPackage::buildMinimumVersion (const std::string
& minimum
)
84 minimum_version_checked
= TRUE
;
85 if (version_compare(setup_version
, minimum
) < 0)
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());
98 IniDBBuilderPackage::buildPackage (const std::string
& _name
)
102 /* Reset for next package */
107 replace_versions
.clear();
109 cbpv
.reponame
= release
;
111 cbpv
.vendor
= release
;
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();
125 currentNodeList
= NULL
;
126 dependsNodeList
= PackageDepends();
127 obsoletesNodeList
= PackageDepends();
128 providesNodeList
= PackageDepends();
129 conflictsNodeList
= PackageDepends();
131 Log (LOG_BABBLE
) << "Created package " << name
<< endLog
;
136 IniDBBuilderPackage::buildPackageVersion (const std::string
& version
)
138 cbpv
.version
= version
;
142 IniDBBuilderPackage::buildPackageSDesc (const std::string
& theDesc
)
144 cbpv
.sdesc
= theDesc
;
148 IniDBBuilderPackage::buildPackageLDesc (const std::string
& theDesc
)
150 cbpv
.ldesc
= theDesc
;
154 IniDBBuilderPackage::buildPackageInstall (const std::string
& path
,
155 const std::string
& size
,
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
));
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;
174 if (hash
&& !cbpv
.archive
.md5
.isSet())
175 cbpv
.archive
.md5
.set((unsigned char *)hash
);
183 const std::string src_suffix
= "-src";
186 IniDBBuilderPackage::buildPackageSource (const std::string
& path
,
187 const std::string
& size
,
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
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
));
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;
223 if (hash
&& !cspv
.archive
.md5
.isSet())
224 cspv
.archive
.md5
.set((unsigned char *)hash
);
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))
239 source_name
= name
+ src_suffix
;
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
;
250 IniDBBuilderPackage::buildPackageTrust (trusts newtrust
)
253 cbpv
.stability
= newtrust
;
257 IniDBBuilderPackage::buildPackageCategory (const std::string
& name
)
259 categories
.insert(name
);
263 IniDBBuilderPackage::buildBeginDepends ()
266 Log (LOG_BABBLE
) << "Beginning of a depends statement " << endLog
;
269 dependsNodeList
= PackageDepends();
270 currentNodeList
= &dependsNodeList
;
271 cbpv
.requires
= &dependsNodeList
;
275 IniDBBuilderPackage::buildBeginBuildDepends ()
278 Log (LOG_BABBLE
) << "Beginning of a Build-Depends statement" << endLog
;
281 currentNodeList
= NULL
;
282 /* there is currently nowhere to store Build-Depends information */
286 IniDBBuilderPackage::buildBeginObsoletes ()
289 Log (LOG_BABBLE
) << "Beginning of an obsoletes statement" << endLog
;
292 obsoletesNodeList
= PackageDepends();
293 currentNodeList
= &obsoletesNodeList
;
294 cbpv
.obsoletes
= &obsoletesNodeList
;
298 IniDBBuilderPackage::buildBeginProvides ()
301 Log (LOG_BABBLE
) << "Beginning of a provides statement" << endLog
;
304 providesNodeList
= PackageDepends();
305 currentNodeList
= &providesNodeList
;
306 cbpv
.provides
= &providesNodeList
;
310 IniDBBuilderPackage::buildBeginConflicts ()
313 Log (LOG_BABBLE
) << "Beginning of a conflicts statement" << endLog
;
316 conflictsNodeList
= PackageDepends();
317 currentNodeList
= &conflictsNodeList
;
318 cbpv
.conflicts
= &conflictsNodeList
;
322 IniDBBuilderPackage::buildSourceName (const std::string
& _name
)
324 // When there is a Source: line, that names a real source package
326 cbpv
.spkg
= PackageSpecification(_name
);
327 cbpv
.spkg_id
= db
.findSourceVersion (PackageSpecification(_name
, cbpv
.version
));
329 Log (LOG_BABBLE
) << "\"" << _name
<< "\" is the source package for " << name
<< "." << endLog
;
334 IniDBBuilderPackage::buildSourceNameVersion (const std::string
& version
)
336 // XXX: should be stored as sourceevr
340 IniDBBuilderPackage::buildPackageListNode (const std::string
& name
)
343 Log (LOG_BABBLE
) << "New node '" << name
<< "' for package list" << endLog
;
346 std::string actual_name
= name
;
347 if (name
== "_self-destruct")
348 actual_name
= "libsolv-self-destruct-pkg()";
350 currentSpec
= new PackageSpecification (actual_name
);
352 currentNodeList
->push_back (currentSpec
);
356 IniDBBuilderPackage::buildPackageListOperator (PackageSpecification::_operators
const &_operator
)
360 currentSpec
->setOperator (_operator
);
362 Log (LOG_BABBLE
) << "Current specification is " << *currentSpec
<< "." <<
369 IniDBBuilderPackage::buildPackageListOperatorVersion (const std::string
& aVersion
)
373 currentSpec
->setVersion (aVersion
);
375 Log (LOG_BABBLE
) << "Current specification is " << *currentSpec
<< "." <<
382 IniDBBuilderPackage::buildMessage (const std::string
& _message_id
, const std::string
& _message_string
)
384 message_id
= _message_id
;
385 message_string
= _message_string
;
389 IniDBBuilderPackage::buildPackageReplaceVersionsList (const std::string
& version
)
391 replace_versions
.insert(version
);
396 IniDBBuilderPackage::process ()
401 if (cbpv
.version
.empty())
404 // no install: line, no package
405 if (!cbpv
.archive
.Canonical())
409 Log (LOG_BABBLE
) << "Finished with package " << name
<< endLog
;
410 Log (LOG_BABBLE
) << "Version " << cbpv
.version
<< endLog
;
413 /* Transfer the accumulated package information to packagedb */
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
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();