From ff8c27864df4f164a234d8cdbd92652ed35e3823 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pablo=20Correa=20G=C3=B3mez?= <ablocorrea@hotmail.com>
Date: Mon, 29 Apr 2024 17:15:11 +0200
Subject: [PATCH 1/5] fix(apk-tools-sys): fix new apk_package structure

---
 apk-tools-sys/src/mapk_package.rs | 59 ++++++++++++-------------------
 1 file changed, 23 insertions(+), 36 deletions(-)

diff --git a/apk-tools-sys/src/mapk_package.rs b/apk-tools-sys/src/mapk_package.rs
index eded8c3..26875bc 100644
--- a/apk-tools-sys/src/mapk_package.rs
+++ b/apk-tools-sys/src/mapk_package.rs
@@ -12,43 +12,47 @@ impl Default for apk_package {
 
 impl ::std::fmt::Debug for apk_package {
     fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
-        write ! (f , "apk_package {{ hash_node: {:?}, foreach_genid: {:?}, __bindgen_anon_1: {:?}, name: {:?}, ipkg: {:?}, version: {:?}, arch: {:?}, license: {:?}, origin: {:?}, maintainer: {:?}, url: {:?}, description: {:?}, commit: {:?}, filename: {:?}, depends: {:?}, install_if: {:?}, provides: {:?}, installed_size: {:?}, size: {:?}, build_time: {:?}, provider_priority: {:?}, repos : {:?}, marked : {:?}, uninstallable : {:?}, cached_non_repository : {:?}, csum: {:?} }}" , self . hash_node , self . foreach_genid , self . __bindgen_anon_1 , self . name , self . ipkg , self . version , self . arch , self . license , self . origin , self . maintainer , self . url , self . description , self . commit , self . filename , self . depends , self . install_if , self . provides , self . installed_size , self . size , self . build_time , self . provider_priority , self . repos() , self . marked() , self . uninstallable() , self . cached_non_repository (), self . csum)
+        write ! (f , "apk_package {{ hash_node: {:?}, name: {:?}, ipkg: {:?}, depends: {:?}, install_if: {:?}, provides: {:?}, version: {:?}, installed_size: {:?}, size: {:?}, __bindgen_anon_1: {:?}, foreach_genid: {:?}, provider_priority: {:?}, repos : {:?}, filename_ndx: {:?}, seen : {:?}, marked : {:?}, uninstallable : {:?}, cached_non_repository : {:?}, csum: {:?}, build_time: {:?}, arch: {:?}, license: {:?}, origin: {:?}, maintainer: {:?}, url: {:?}, description: {:?}, commit: {:?} }}" , self . hash_node , self . name , self . ipkg , self . depends , self . install_if , self . provides , self . version , self . installed_size , self . size , self . __bindgen_anon_1 , self . foreach_genid , self . provider_priority , self . repos , self . filename_ndx , self . seen() , self . marked() , self . uninstallable() , self . cached_non_repository (), self . csum ,  self . build_time , self . arch , self . license , self . origin , self . maintainer , self . url , self . description , self . commit)
     }
 }
 
 // can't be auto-generated since the bitfields aren't correctly generated by bindgen#
-// (they shoul be 5 bytes big in total, bindgen makes them take up 8)
+// (they shoul be 4 bytes big in total, bindgen makes them take up 8). Is this
+// still the case??
 
 #[repr(C)]
 pub struct apk_package {
     pub hash_node: apk_hash_node,
-    pub foreach_genid: ::std::os::raw::c_uint,
-    __bindgen_anon_1: apk_package__bindgen_ty_1,
     pub name: *mut apk_name,
     pub ipkg: *mut apk_installed_package,
-    pub version: *mut apk_blob_t,
-    pub arch: *mut apk_blob_t,
-    pub license: *mut apk_blob_t,
-    pub origin: *mut apk_blob_t,
-    pub maintainer: *mut apk_blob_t,
-    pub url: *mut ::std::os::raw::c_char,
-    pub description: *mut ::std::os::raw::c_char,
-    pub commit: *mut ::std::os::raw::c_char,
-    pub filename: *mut ::std::os::raw::c_char,
     pub depends: *mut apk_dependency_array,
     pub install_if: *mut apk_dependency_array,
     pub provides: *mut apk_dependency_array,
+    pub version: *mut apk_blob_t,
     pub installed_size: usize,
     pub size: usize,
-    pub build_time: time_t,
+
+    __bindgen_anon_1: apk_package__bindgen_ty_1,
+    pub foreach_genid: ::std::os::raw::c_uint,
     pub provider_priority: ::std::os::raw::c_ushort,
+    pub repos: ::std::os::raw::c_ushort,
+    pub filename_ndx: ::std::os::raw::c_ushort,
     bitfields: private::apk_package_bitfield,
     pub csum: apk_checksum,
+
+    pub build_time: time_t,
+    pub arch: *mut apk_blob_t,
+    pub license: *mut apk_blob_t,
+    pub origin: *mut apk_blob_t,
+    pub maintainer: *mut apk_blob_t,
+    pub url: *mut ::std::os::raw::c_char,
+    pub description: *mut ::std::os::raw::c_char,
+    pub commit: *mut ::std::os::raw::c_char,
 }
 
 impl apk_package {
-    pub fn repos(&self) -> u32 {
-        self.bitfields.repos()
+    pub fn seen(&self) -> u8 {
+        self.bitfields.seen()
     }
 
     pub fn marked(&self) -> u8 {
@@ -63,8 +67,8 @@ impl apk_package {
         self.bitfields.cached_non_repository()
     }
 
-    pub fn set_repos(&mut self, val: u32) {
-        self.bitfields.set_repos(val)
+    pub fn set_seen(&mut self, val: u8) {
+        self.bitfields.set_seen(val)
     }
 
     pub fn set_marked(&mut self, val: u8) {
@@ -85,7 +89,7 @@ mod private {
     #[modular_bitfield::bitfield]
     #[repr(C)]
     pub struct apk_package_bitfield {
-        pub repos: u32,
+        pub seen: u8,
         pub marked: u8,
         pub uninstallable: u8,
         pub cached_non_repository: u8,
@@ -312,23 +316,6 @@ mod test {
             );
         }
         test_field_commit();
-        fn test_field_filename() {
-            assert_eq!(
-                unsafe {
-                    let uninit = ::std::mem::MaybeUninit::<apk_package>::uninit();
-                    let ptr = uninit.as_ptr();
-                    ::std::ptr::addr_of!((*ptr).filename) as usize - ptr as usize
-                },
-                112usize,
-                concat!(
-                    "Offset of field: ",
-                    stringify!(apk_package),
-                    "::",
-                    stringify!(filename)
-                )
-            );
-        }
-        test_field_filename();
         fn test_field_depends() {
             assert_eq!(
                 unsafe {
-- 
2.45.0

