public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: "'Cedric Hombourger' via isar-users" <isar-users@googlegroups.com>
To: isar-users@googlegroups.com
Cc: Cedric Hombourger <cedric.hombourger@siemens.com>
Subject: [PATCH 3/3] repository: make repo_contains_package query the package database
Date: Fri, 22 Nov 2024 06:48:16 +0100	[thread overview]
Message-ID: <20241122054816.3371334-4-cedric.hombourger@siemens.com> (raw)
In-Reply-To: <20241122054816.3371334-1-cedric.hombourger@siemens.com>

Debian package repositories (created/updated with dak) and reprepro
repositories do not have the same file naming convention (e.g. the
latter does not use Epoch). A full directory scan may also be
expensive for large repositories: use reprepro listfilter to check
for matching packages in the database.

Signed-off-by: Cedric Hombourger <cedric.hombourger@siemens.com>
---
 meta/classes/repository.bbclass | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/meta/classes/repository.bbclass b/meta/classes/repository.bbclass
index b20ec091..bc5852a5 100644
--- a/meta/classes/repository.bbclass
+++ b/meta/classes/repository.bbclass
@@ -98,7 +98,28 @@ repo_contains_package() {
     local file="$4"
     local package
 
-    package=$(find ${dir} -name ${file##*/})
+    # Extract meta-data from the provided .deb file
+    package=$(dpkg-deb -f ${file} Package Version Architecture)
+
+    # Output for each field is "Field: Value"
+    # odd indexes hold field names, even indexes hold values
+    set -- ${package}
+
+    # lookup ${file} in the database for the current suite
+    package=$(reprepro -b ${dir} --dbdir ${dbdir} \
+                       --list-format '${$fullfilename}\n' \
+                       listfilter ${codename} '
+                           Package (= '${2}'),
+                           Version (= '${4}'),
+                           Architecture (= '${6}'),
+                           $PackageType (= deb)')
+
+    # we only need the first match (should there be more). Use shell builtins to avoid
+    # spawning an additional process (e.g. "head")
+    set -- ${package}
+    package="${1}"
+
+    # package found in the database?
     if [ -n "$package" ]; then
         # yes
         cmp --silent "$package" "$file" && return 0
-- 
2.34.1

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/isar-users/20241122054816.3371334-4-cedric.hombourger%40siemens.com.

  parent reply	other threads:[~2024-11-22  5:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-22  5:48 [PATCH 0/3] repository: small fixes for repo_{contains,del}_packages 'Cedric Hombourger' via isar-users
2024-11-22  5:48 ` [PATCH 1/3] repository: repo_del_package should not remove source packages 'Cedric Hombourger' via isar-users
2024-11-22  5:48 ` [PATCH 2/3] repository: align repo_contains_package signature with other repo functions 'Cedric Hombourger' via isar-users
2024-11-22  5:48 ` 'Cedric Hombourger' via isar-users [this message]
2024-11-27  7:11 ` [PATCH 0/3] repository: small fixes for repo_{contains,del}_packages Uladzimir Bely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241122054816.3371334-4-cedric.hombourger@siemens.com \
    --to=isar-users@googlegroups.com \
    --cc=cedric.hombourger@siemens.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox