From 72f3c7e0bb7440aa8324627248770dc721d929f4 Mon Sep 17 00:00:00 2001 From: Sergey Konev Date: Wed, 23 Oct 2024 14:15:22 +0300 Subject: [PATCH 1/7] Fixed some declarations and marked some funcs as TODO --- apt-pkg-c/lib.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apt-pkg-c/lib.cpp b/apt-pkg-c/lib.cpp index 7c478d0..4a61b01 100644 --- a/apt-pkg-c/lib.cpp +++ b/apt-pkg-c/lib.cpp @@ -73,7 +73,14 @@ struct PVerFileParser { extern "C" { void init_config_system(); + #ifndef ALT_LINUX PCache *pkg_cache_create(); + #else + PCache *pkg_cache_create(const bool WithLock, OpProgress &Progress); + #endif + + + void pkg_cache_release(PCache *cache); int32_t pkg_cache_compare_versions(PCache *cache, const char *left, const char *right); @@ -81,7 +88,12 @@ extern "C" { // pkg_iter creation and deletion PPkgIterator *pkg_cache_pkg_iter(PCache *cache); PPkgIterator *pkg_cache_find_name(PCache *cache, const char *name); + #ifndef ALT_LINUX PPkgIterator *pkg_cache_find_name_arch(PCache *cache, const char *name, const char *arch); + #else + PPkgIterator *pkg_cache_find_name_arch(PCache *cache, const char *name); + #endif + void pkg_iter_release(PPkgIterator *iterator); // pkg_iter mutation @@ -89,10 +101,15 @@ extern "C" { bool pkg_iter_end(PPkgIterator *iterator); // pkg_iter access + // TODO: Implement for ALT_LINUX const char *pkg_iter_name(PPkgIterator *iterator); 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 @@ -110,6 +127,7 @@ extern "C" { const char *ver_iter_priority_type(PVerIterator *wrapper); #ifndef YE_OLDE_APT + // TODO: Implement for ALT_LINUX const char *ver_iter_source_package(PVerIterator *iterator); const char *ver_iter_source_version(PVerIterator *iterator); int32_t ver_iter_priority(PVerIterator *iterator); @@ -144,6 +162,7 @@ extern "C" { const char *ver_file_parser_short_desc(PVerFileParser *parser); const char *ver_file_parser_long_desc(PVerFileParser *parser); const char *ver_file_parser_maintainer(PVerFileParser *parser); + // TODO: Implementation and declaration for ALT_LINUX const char *ver_file_parser_homepage(PVerFileParser *parser); // ver_file_iter has no accessors, only the creation of pkg_file_iter @@ -162,7 +181,9 @@ extern "C" { const char *pkg_file_iter_archive(PPkgFileIterator *iterator); const char *pkg_file_iter_version(PPkgFileIterator *iterator); 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); -- 2.42.2 From 35f831435f28060fc7909aad6a339860724619e5 Mon Sep 17 00:00:00 2001 From: Sergey Konev Date: Wed, 23 Oct 2024 19:00:24 +0300 Subject: [PATCH 2/7] Redisigned few functions --- .gitignore | 4 +++ apt-pkg-c/lib.cpp | 77 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 65 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index 761daa9..ab2041a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ Cargo.lock *.iml apt-c/lib.o apt-c/libapt-c.a + +.clangd +compile_commands.json +.vscode \ No newline at end of file diff --git a/apt-pkg-c/lib.cpp b/apt-pkg-c/lib.cpp index 4a61b01..48c4ff8 100644 --- a/apt-pkg-c/lib.cpp +++ b/apt-pkg-c/lib.cpp @@ -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) { -- 2.42.2 From c7c7159bb1d455f854e3f00b46490e46346dec25 Mon Sep 17 00:00:00 2001 From: kozorizki Date: Thu, 24 Oct 2024 11:46:21 +0300 Subject: [PATCH 3/7] fix(raw.rs): pkg_cache_find_name_arch function signature Removed from the function signature the parameter (arch: *const c_char) --- src/raw.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/raw.rs b/src/raw.rs index 28bcad9..a599a44 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -38,7 +38,6 @@ extern "C" { pub fn pkg_cache_find_name_arch( cache: PCache, name: *const c_char, - arch: *const c_char, ) -> PPkgIterator; pub fn pkg_iter_release(iterator: PPkgIterator); -- 2.42.2 From 9a359a5e634c85c3671efe863aa5b3948b7e7898 Mon Sep 17 00:00:00 2001 From: kozorizki Date: Thu, 24 Oct 2024 11:46:21 +0300 Subject: [PATCH 4/7] fix(raw.rs): pkg_cache_find_name_arch function signature Removed from the function signature the parameter (arch: *const c_char) for alt-linux cfg --- src/raw.rs | 7 +++++++ src/sane.rs | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/raw.rs b/src/raw.rs index a599a44..e743773 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -35,10 +35,17 @@ extern "C" { pub fn pkg_cache_pkg_iter(cache: PCache) -> PPkgIterator; pub fn pkg_cache_find_name(cache: PCache, name: *const c_char) -> PPkgIterator; + #[cfg(feature = "alt-linux")] pub fn pkg_cache_find_name_arch( cache: PCache, name: *const c_char, ) -> PPkgIterator; + #[cfg(not(feature = "alt-linux"))] + pub fn pkg_cache_find_name_arch( + cache: PCache, + name: *const c_char, + ) -> PPkgIterator; + pub fn pkg_iter_release(iterator: PPkgIterator); pub fn pkg_iter_next(iterator: PPkgIterator); diff --git a/src/sane.rs b/src/sane.rs index f0eecf5..cfffc2e 100644 --- a/src/sane.rs +++ b/src/sane.rs @@ -66,7 +66,13 @@ impl Cache { unsafe { let name = ffi::CString::new(name).unwrap(); let arch = ffi::CString::new(arch).unwrap(); + + #[cfg(feature = "alt-linux")] + let ptr = raw::pkg_cache_find_name_arch(lock.ptr, name.as_ptr()); + + #[cfg(not(feature = "alt-linux"))] let ptr = raw::pkg_cache_find_name_arch(lock.ptr, name.as_ptr(), arch.as_ptr()); + PkgIterator::new(lock, ptr) } } -- 2.42.2 From 72edc80e94b7b95b193b3e7e12a9e7a0d0ce41c9 Mon Sep 17 00:00:00 2001 From: Sergey Konev Date: Thu, 24 Oct 2024 14:28:30 +0300 Subject: [PATCH 5/7] First approach (source_version function remains unimplemented for now) --- apt-pkg-c/lib.cpp | 57 +++++++++++++++++++++++++++++++---------------- src/raw.rs | 6 +++-- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/apt-pkg-c/lib.cpp b/apt-pkg-c/lib.cpp index 48c4ff8..c8635ff 100644 --- a/apt-pkg-c/lib.cpp +++ b/apt-pkg-c/lib.cpp @@ -73,11 +73,7 @@ struct PVerFileParser { extern "C" { void init_config_system(); - #ifndef ALT_LINUX PCache *pkg_cache_create(); - #else - PCache *pkg_cache_create(const bool WithLock, OpProgress &Progress); - #endif @@ -103,7 +99,6 @@ extern "C" { // pkg_iter access 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); const char *pkg_iter_candidate_version(PPkgIterator *iterator); @@ -121,9 +116,8 @@ extern "C" { const char *ver_iter_section(PVerIterator *iterator); const char *ver_iter_arch(PVerIterator *iterator); const char *ver_iter_priority_type(PVerIterator *wrapper); - + #ifndef YE_OLDE_APT - // TODO: Implement for ALT_LINUX const char *ver_iter_source_package(PVerIterator *iterator); const char *ver_iter_source_version(PVerIterator *iterator); int32_t ver_iter_priority(PVerIterator *iterator); @@ -158,7 +152,6 @@ extern "C" { const char *ver_file_parser_short_desc(PVerFileParser *parser); const char *ver_file_parser_long_desc(PVerFileParser *parser); const char *ver_file_parser_maintainer(PVerFileParser *parser); - // TODO: Implementation and declaration for ALT_LINUX const char *ver_file_parser_homepage(PVerFileParser *parser); // ver_file_iter has no accessors, only the creation of pkg_file_iter @@ -177,7 +170,6 @@ extern "C" { const char *pkg_file_iter_archive(PPkgFileIterator *iterator); const char *pkg_file_iter_version(PPkgFileIterator *iterator); 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); @@ -209,9 +201,17 @@ PCache *pkg_cache_create() { #else -PCache *pkg_cache_create(const bool WithLock, OpProgress &Progress) { +PCache *pkg_cache_create() { + // Maybe should be set to false sometimes + // (Set to true always for now) + // We should lock for installation, etc. + // For read-only access no locking needed + // Ideally locking semantic should be simillar to ALT's apt CLI + const bool WithLock = true; + pkgCacheFile *cache_file = new pkgCacheFile(WithLock); - pkgCache *cache = cache_file->GetPkgCache(Progress); + // there is a cast operator from pkgCacheFile to pkgCache* + pkgCache *cache = *cache_file; pkgRecords *records = new pkgRecords(*cache); PCache *ret = new PCache(); @@ -404,12 +404,20 @@ int32_t ver_iter_priority(PVerIterator *wrapper) { #endif #ifdef ALT_LINUX -const char *ver_iter_source_package(PVerIterator *wrapper) { - return wrapper->iterator.SourcePkgName(); +const char *to_c_string(std::string s); + +const char *ver_iter_source_package(PVerIterator *wrapper) { + pkgRecords *recs = wrapper->cache->records; + pkgRecords::Parser &parse = recs->Lookup(wrapper->iterator.FileList()); + + // It's okay to return raw pointer to heap memory, due to convention in Rust-caller + // (it will be freed by an owning wrapper) + return to_c_string(parse.SourcePkg()); } const char *ver_iter_source_version(PVerIterator *wrapper) { - return wrapper->iterator.SourceVerStr(); + // TODO: haven't found a way to get source version yet! + return to_c_string("Not Specified"); } int32_t ver_iter_priority(PVerIterator *wrapper) { @@ -511,16 +519,20 @@ const char *ver_file_parser_maintainer(PVerFileParser *parser) { #ifndef ALT_LINUX const char *ver_file_parser_homepage(PVerFileParser *parser) { - std::string hp = parser->parser->Homepage(); - return to_c_string(hp); + 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); + // Unimplementable in ALT via PVerFileParser + // Maybe should remove it in ALT version of lib (or just return nullptr) + // Not sure in use of nullptr due to possible absense of checks from caller + // So return dummy string + return to_c_string("Not Specified"); } #endif + bool ver_file_iter_end(PVerFileIterator *wrapper) { return wrapper->iterator.end(); } @@ -562,9 +574,16 @@ const char *pkg_file_iter_origin(PPkgFileIterator *wrapper) { #ifndef ALT_LINUX const char *pkg_file_iter_codename(PPkgFileIterator *wrapper) { - return wrapper->iterator.Codename(); + return wrapper->iterator.Codename(); } +#else +const char *pkg_file_iter_codename(PPkgFileIterator *wrapper) { + // From Debian docs: + /* "The Codename field shall describe the codename of the release.*/ + // Analogues in ALT is Branch name. + return wrapper->iterator.Label(); +} #endif const char *pkg_file_iter_label(PPkgFileIterator *wrapper) { diff --git a/src/raw.rs b/src/raw.rs index e743773..79370f8 100644 --- a/src/raw.rs +++ b/src/raw.rs @@ -35,12 +35,14 @@ extern "C" { pub fn pkg_cache_pkg_iter(cache: PCache) -> PPkgIterator; pub fn pkg_cache_find_name(cache: PCache, name: *const c_char) -> PPkgIterator; - #[cfg(feature = "alt-linux")] + + #[cfg(not(feature = "alt-linux"))] pub fn pkg_cache_find_name_arch( cache: PCache, name: *const c_char, + arch: *const c_char, ) -> PPkgIterator; - #[cfg(not(feature = "alt-linux"))] + #[cfg(feature = "alt-linux")] pub fn pkg_cache_find_name_arch( cache: PCache, name: *const c_char, -- 2.42.2 From 07f8a400f2d354bf1e8dbeef474434a500972bd2 Mon Sep 17 00:00:00 2001 From: Sergey Konev Date: Fri, 25 Oct 2024 13:56:17 +0300 Subject: [PATCH 6/7] Adapted library for ALT's apt --- apt-pkg-c/lib.cpp | 88 +++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 29 deletions(-) diff --git a/apt-pkg-c/lib.cpp b/apt-pkg-c/lib.cpp index c8635ff..136112c 100644 --- a/apt-pkg-c/lib.cpp +++ b/apt-pkg-c/lib.cpp @@ -14,7 +14,11 @@ struct PCache { // Owned by us. + #ifndef ALT_LINUX pkgCacheFile *cache_file; + #else + CacheFile *cache_file; + #endif // Borrowed from cache_file. pkgCache *cache; @@ -74,9 +78,6 @@ extern "C" { void init_config_system(); PCache *pkg_cache_create(); - - - void pkg_cache_release(PCache *cache); int32_t pkg_cache_compare_versions(PCache *cache, const char *left, const char *right); @@ -89,7 +90,6 @@ extern "C" { #else PPkgIterator *pkg_cache_find_name_arch(PCache *cache, const char *name); #endif - void pkg_iter_release(PPkgIterator *iterator); // pkg_iter mutation @@ -98,7 +98,6 @@ extern "C" { // pkg_iter access const char *pkg_iter_name(PPkgIterator *iterator); - const char *pkg_iter_arch(PPkgIterator *iterator); const char *pkg_iter_current_version(PPkgIterator *iterator); const char *pkg_iter_candidate_version(PPkgIterator *iterator); @@ -200,17 +199,37 @@ PCache *pkg_cache_create() { } #else +const char *to_c_string(std::string s); + +#include +bool can_commit() { + // Allow user with effective SU to acquire lock + return geteuid() == 0; +} + + +// See ALT's apt/cmdline +// Used to print out the progress +// Set to stdout for now +ostream progress_stream(0); PCache *pkg_cache_create() { // Maybe should be set to false sometimes - // (Set to true always for now) + // (Set to can_commit() for now) // We should lock for installation, etc. // For read-only access no locking needed - // Ideally locking semantic should be simillar to ALT's apt CLI - const bool WithLock = true; + // In apt-shell, WithLock is always set according to (geteuid() == 0). + const bool WithLock = can_commit(); - pkgCacheFile *cache_file = new pkgCacheFile(WithLock); - // there is a cast operator from pkgCacheFile to pkgCache* + CacheFile *cache_file = new CacheFile(progress_stream, WithLock); + cache_file->Open(); + + if (cache_file->CheckDeps(true) == false) { + delete cache_file; + return nullptr; + } + + // cast operator from CacheFile to pkgCache* pkgCache *cache = *cache_file; pkgRecords *records = new pkgRecords(*cache); @@ -306,28 +325,36 @@ const char *pkg_iter_candidate_version(PPkgIterator *wrapper) { #else - -// 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; + pkgCache::VerIterator it = wrapper->iterator.VersionList(); if (it.end()) { - return nullptr; + // It's a virtual package + // Let's take some of providers and take it's arch + pkgCache::PrvIterator provide_list = wrapper->iterator.ProvidesList(); + if (provide_list.end()) { + // Return 'something' in case of broken packages + // I would prefer returning nullptr, + // but Rust-side requires it to be non-null + return to_c_string("Undefined"); + } + pkgCache::PkgIterator provide = provide_list.OwnerPkg(); + if (provide.end()) { + return to_c_string("Undefined"); + } + + PPkgIterator new_wrapper; + new_wrapper.iterator = provide; + new_wrapper.cache = wrapper->cache; + + return pkg_iter_arch(&new_wrapper); + } else { + return it.Arch(); } - return it.Arch(); } const char *pkg_iter_current_version(PPkgIterator *wrapper) { - pkgCache::VerIterator it = create_ver_iter(wrapper).iterator; + pkgCache::VerIterator it = wrapper->iterator.CurrentVer(); if (it.end()) { return nullptr; @@ -337,7 +364,7 @@ const char *pkg_iter_current_version(PPkgIterator *wrapper) { 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) + // Getting rid of GetPolicy call by creating PkgPolicy object via 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); @@ -404,7 +431,6 @@ int32_t ver_iter_priority(PVerIterator *wrapper) { #endif #ifdef ALT_LINUX -const char *to_c_string(std::string s); const char *ver_iter_source_package(PVerIterator *wrapper) { pkgRecords *recs = wrapper->cache->records; @@ -415,9 +441,10 @@ const char *ver_iter_source_package(PVerIterator *wrapper) { return to_c_string(parse.SourcePkg()); } +// SHOULD BE REMOVED FROM ALT'S VERSION! MEANINGLESS! +// Apt only works with rpms and not src.rpm const char *ver_iter_source_version(PVerIterator *wrapper) { - // TODO: haven't found a way to get source version yet! - return to_c_string("Not Specified"); + return wrapper->iterator.VerStr(); } int32_t ver_iter_priority(PVerIterator *wrapper) { @@ -523,6 +550,9 @@ const char *ver_file_parser_homepage(PVerFileParser *parser) { return to_c_string(hp); } #else + +// Should be erased from Alt's version or Alt's Apt should provide +// functionality for getting homepage address const char *ver_file_parser_homepage(PVerFileParser *parser) { // Unimplementable in ALT via PVerFileParser // Maybe should remove it in ALT version of lib (or just return nullptr) -- 2.42.2 From c8a0505ff7c7ee1c4e5e4751c5dfed71d890c764 Mon Sep 17 00:00:00 2001 From: Sergey Konev Date: Fri, 25 Oct 2024 14:51:16 +0300 Subject: [PATCH 7/7] Minor binding fix to work with nullptr --- apt-pkg-c/lib.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/apt-pkg-c/lib.cpp b/apt-pkg-c/lib.cpp index 136112c..90e6a91 100644 --- a/apt-pkg-c/lib.cpp +++ b/apt-pkg-c/lib.cpp @@ -589,9 +589,20 @@ const char *pkg_file_iter_file_name(PPkgFileIterator *wrapper) { return wrapper->iterator.FileName(); } +#ifndef ALT_LINUX const char *pkg_file_iter_archive(PPkgFileIterator *wrapper) { return wrapper->iterator.Archive(); } +#else +const char *pkg_file_iter_archive(PPkgFileIterator *wrapper) { + const char *archive = wrapper->iterator.Archive(); + if (archive == nullptr) { + // Should be non-null + return to_c_string("Not Specified"); + } + return archive; +} +#endif const char *pkg_file_iter_version(PPkgFileIterator *wrapper) { return wrapper->iterator.Version(); @@ -624,14 +635,37 @@ const char *pkg_file_iter_site(PPkgFileIterator *wrapper) { return wrapper->iterator.Site(); } +#ifndef ALT_LINUX const char *pkg_file_iter_component(PPkgFileIterator *wrapper) { return wrapper->iterator.Component(); } +#else +const char *pkg_file_iter_component(PPkgFileIterator *wrapper) { + const char *component = wrapper->iterator.Component(); + if (component == nullptr) { + // Should be non-null + return to_c_string("Not Specified"); + } + return component; +} + +#endif const char *pkg_file_iter_architecture(PPkgFileIterator *wrapper) { return wrapper->iterator.Architecture(); } +#ifndef ALT_LINUX const char *pkg_file_iter_index_type(PPkgFileIterator *wrapper) { return wrapper->iterator.IndexType(); } +#else +const char *pkg_file_iter_index_type(PPkgFileIterator *wrapper) { + const char *index_type = wrapper->iterator.IndexType(); + if (index_type == nullptr) { + // Should be non-null + return to_c_string("Not Specified"); + } + return index_type; +} +#endif -- 2.42.2