[elbe-devel] [PATCH] elbepack: drop the custom implementation of fetch_binary

Thomas Weißschuh thomas.weissschuh at linutronix.de
Fri Mar 15 08:59:46 CET 2024


The bug fixed by the custom implementation should be fixed since at
least bullseye.

Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
 elbepack/aptpkgutils.py                | 52 ----------------------------------
 elbepack/commands/fetch_initvm_pkgs.py |  6 ++--
 elbepack/rpcaptcache.py                |  5 +---
 3 files changed, 3 insertions(+), 60 deletions(-)

diff --git a/elbepack/aptpkgutils.py b/elbepack/aptpkgutils.py
index 37cf8489e3d5..817fae4c4629 100644
--- a/elbepack/aptpkgutils.py
+++ b/elbepack/aptpkgutils.py
@@ -3,7 +3,6 @@
 # SPDX-FileCopyrightText: 2005-2009 Canonical
 # SPDX-FileCopyrightText: 2014, 2017 Linutronix GmbH
 
-import logging
 import os
 
 import apt
@@ -95,57 +94,6 @@ def pkgorigin(pkg):
     return origin
 
 
-def _file_is_same(path, size, sha256):
-    """Return ``True`` if the file is the same."""
-    if os.path.exists(path) and os.path.getsize(path) == size:
-        with open(path) as fobj:
-            return apt_pkg.sha256sum(fobj) == sha256
-    return False
-
-
-def fetch_binary(version, destdir='', progress=None):
-    """Fetch the binary version of the package.
-
-    The parameter *destdir* specifies the directory where the package will
-    be fetched to.
-
-    The parameter *progress* may refer to an apt_pkg.AcquireProgress()
-    object. If not specified or None, apt.progress.text.AcquireProgress()
-    is used.
-
-    taken from python-apt-1.8.4
-    https://salsa.debian.org/apt-team/python-apt/-/blob/1.8.4/apt/package.py
-
-    ---------------------------------------------------------
-    Copyright (c) 2005-2009 Canonical
-
-    Author: Michael Vogt <michael.vogt at ubuntu.com>
-    ---------------------------------------------------------
-
-    Then fixed up to use sha256 and pass pycodestyle.
-    """
-    base = os.path.basename(version._records.filename)
-    destfile = os.path.join(destdir, base)
-    if _file_is_same(destfile, version.size, version._records.sha256_hash):
-        logging.debug('Ignoring already existing file: %s', destfile)
-        return os.path.abspath(destfile)
-    acq = apt_pkg.Acquire(progress or apt.progress.text.AcquireProgress())
-    acqfile = apt_pkg.AcquireFile(acq,
-                                  version.uri,
-                                  'SHA256:' + version._records.sha256_hash,
-                                  version.size,
-                                  base,
-                                  destfile=destfile)
-    acq.run()
-
-    if acqfile.status != acqfile.STAT_DONE:
-        raise FetchError(
-            f'The item {acqfile.destfile} could not be fetched: '
-            f'{acqfile.error_text}')
-
-    return os.path.abspath(destfile)
-
-
 def fetch_source(name, version, destdir, progress=None):
 
     allow_untrusted = apt_pkg.config.find_b('APT::Get::AllowUnauthenticated', False)
diff --git a/elbepack/commands/fetch_initvm_pkgs.py b/elbepack/commands/fetch_initvm_pkgs.py
index 6a67c04e9e3c..e75b005673e4 100644
--- a/elbepack/commands/fetch_initvm_pkgs.py
+++ b/elbepack/commands/fetch_initvm_pkgs.py
@@ -9,7 +9,7 @@ from optparse import OptionParser
 from apt import Cache
 from apt.package import FetchError
 
-from elbepack.aptpkgutils import fetch_binary, fetch_source, get_corresponding_source_packages
+from elbepack.aptpkgutils import fetch_source, get_corresponding_source_packages
 from elbepack.aptprogress import ElbeAcquireProgress
 from elbepack.dump import get_initvm_pkglist
 from elbepack.elbexml import ElbeXML, ValidationError
@@ -109,9 +109,7 @@ def run_command(argv):
                     try:
                         p = cache[pkg.name]
                         pkgver = p.installed
-                        deb = fetch_binary(pkgver,
-                                           opt.archive,
-                                           ElbeAcquireProgress(cb=None))
+                        deb = pkgver.fetch_binary(opt.archive, ElbeAcquireProgress(cb=None))
                         repo.includedeb(deb, 'main', prio=pkgver.priority)
                         break
                     except ValueError:
diff --git a/elbepack/rpcaptcache.py b/elbepack/rpcaptcache.py
index 3ed460353ff0..b9985414091f 100644
--- a/elbepack/rpcaptcache.py
+++ b/elbepack/rpcaptcache.py
@@ -15,7 +15,6 @@ from apt_pkg import config, version_compare
 
 from elbepack.aptpkgutils import (
     APTPackage,
-    fetch_binary,
     fetch_source,
     get_corresponding_source_packages,
     getalldeps,
@@ -332,9 +331,7 @@ class RPCAPTCache(InChRootObject):
             pkgver = p.installed
         else:
             pkgver = p.versions[version]
-        rel_filename = fetch_binary(pkgver,
-                                    path,
-                                    ElbeAcquireProgress())
+        rel_filename = pkgver.fetch_binary(path, ElbeAcquireProgress())
         return self.rfs.fname(rel_filename)
 
     def download_source(self, src_name, src_version, dest_dir):

---
base-commit: ef9eeca734b372faba47b88df94950d5b465751d
change-id: 20240314-fetch_binary-d7f6084b02e3

Best regards,
-- 
Thomas Weißschuh <thomas.weissschuh at linutronix.de>



More information about the elbe-devel mailing list