Redisigned few functions

This commit is contained in:
Сергей Конев 2024-10-23 19:00:24 +03:00
parent 72f3c7e0bb
commit 35f831435f
2 changed files with 65 additions and 16 deletions

4
.gitignore vendored
View File

@ -5,3 +5,7 @@ Cargo.lock
*.iml
apt-c/lib.o
apt-c/libapt-c.a
.clangd
compile_commands.json
.vscode

View File

@ -101,16 +101,12 @@ extern "C" {
bool pkg_iter_end(PPkgIterator *iterator);
// pkg_iter access
// TODO: Implement for ALT_LINUX
const char *pkg_iter_name(PPkgIterator *iterator);
// TODO: Implement for ALT_LINUX (DONE)
const char *pkg_iter_arch(PPkgIterator *iterator);
const char *pkg_iter_current_version(PPkgIterator *iterator);
#ifndef ALT_LINUX
const char *pkg_iter_candidate_version(PPkgIterator *iterator);
#else
const char *pkg_iter_candidate_version(PPkgIterator *wrapper, OpProgress &Progress);
#endif
// ver_iter creation and deletion
PVerIterator *pkg_iter_ver_iter(PPkgIterator *iterator);
@ -183,7 +179,7 @@ extern "C" {
const char *pkg_file_iter_origin(PPkgFileIterator *iterator);
// TODO: Implementation and declaration for ALT_LINUX
const char *pkg_file_iter_codename(PPkgFileIterator *iterator);
const char *pkg_file_iter_label(PPkgFileIterator *iterator);
const char *pkg_file_iter_site(PPkgFileIterator *iterator);
const char *pkg_file_iter_component(PPkgFileIterator *iterator);
@ -310,16 +306,42 @@ const char *pkg_iter_candidate_version(PPkgIterator *wrapper) {
#else
// const char *pkg_iter_arch(PPkgIterator *wrapper) {
// return wrapper->iterator.Arch();
// }
// const char *pkg_iter_current_version(PPkgIterator *wrapper) {
// return wrapper->iterator.CurVersion();
// }
// Creates PVerIterator using PPkgIterator data
// (implementation taken from pkg_iter_ver_iter())
PVerIterator create_ver_iter(PPkgIterator *pkg_wrapper) {
PVerIterator ver_wrapper;
ver_wrapper.iterator = pkg_wrapper->iterator.VersionList();
ver_wrapper.pkg = &pkg_wrapper->iterator;
ver_wrapper.cache = pkg_wrapper->cache;
return ver_wrapper;
}
const char *pkg_iter_arch(PPkgIterator *wrapper) {
pkgCache::VerIterator it = create_ver_iter(wrapper).iterator;
if (it.end()) {
return nullptr;
}
return it.Arch();
}
const char *pkg_iter_current_version(PPkgIterator *wrapper) {
pkgCache::VerIterator it = create_ver_iter(wrapper).iterator;
if (it.end()) {
return nullptr;
}
return it.VerStr();
}
const char *pkg_iter_candidate_version(PPkgIterator *wrapper) {
// pkgCache::VerIterator it = wrapper->cache->cache_file->GetPolicy(Progress)->GetCandidateVer(wrapper->iterator);
// Getting rid of GetPolicy call by creating PkgPolicy object with constructor (no need in OpProgress)
// (This is done this way in cmdline apt utility (see ALT's apt/cmdline sources))
pkgPolicy plcy(wrapper->cache->cache);
pkgCache::VerIterator it = plcy.GetCandidateVer(wrapper->iterator);
const char *pkg_iter_candidate_version(PPkgIterator *wrapper, OpProgress &Progress) {
pkgCache::VerIterator it = wrapper->cache->cache_file->GetPolicy(Progress)->GetCandidateVer(wrapper->iterator);
if (it.end()) {
return nullptr;
}
@ -381,6 +403,25 @@ int32_t ver_iter_priority(PVerIterator *wrapper) {
#endif
#endif
#ifdef ALT_LINUX
const char *ver_iter_source_package(PVerIterator *wrapper) {
return wrapper->iterator.SourcePkgName();
}
const char *ver_iter_source_version(PVerIterator *wrapper) {
return wrapper->iterator.SourceVerStr();
}
int32_t ver_iter_priority(PVerIterator *wrapper) {
// return wrapper->cache->cache_file->GetPolicy(Progress)->GetPriority(*wrapper->pkg);
// Getting rid of GetPolicy call by creating PkgPolicy object with constructor (no need in OpProgress)
// (This is done this way in cmdline apt utility (see ALT's apt/cmdline sources))
pkgPolicy plcy(wrapper->cache->cache);
return plcy.GetPriority(*wrapper->pkg);
}
#endif
const char *ver_iter_arch(PVerIterator *wrapper) {
return wrapper->iterator.Arch();
}
@ -473,7 +514,11 @@ const char *ver_file_parser_homepage(PVerFileParser *parser) {
std::string hp = parser->parser->Homepage();
return to_c_string(hp);
}
#else
const char *ver_file_parser_homepage(PVerFileParser *parser) {
std::string hp = parser->parser->Homepage();
return to_c_string(hp);
}
#endif
bool ver_file_iter_end(PVerFileIterator *wrapper) {