[Yum-devel] [PATCH 2/2] background downloading with --downloadonly

Zdeněk Pavlas zpavlas at redhat.com
Fri Oct 12 13:33:59 UTC 2012


- just temp rpm files, no temporary directories
- 'predownload' hook runs when 'yum.pid' lock is still held
- 'postdownload' hook is skipped if we run downloadonly

It may be worth to relock after downloading, save partial downloads,
and run postdownload hooks, not sure.

predownload hooks run when locked, so this does not break presto,
but drpms download in foreground.  Finally a good reason to move
it to core :)
---
 yum/__init__.py |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/yum/__init__.py b/yum/__init__.py
index 1479d33..03b9c2c 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2241,6 +2241,10 @@ much more problems).
                     self.verbose_logger.debug(_("using local copy of %s") %(po,))
                     continue
                         
+            if downloadonly:
+                # download to temp file
+                po.localpath += '.%d.tmp' % os.getpid()
+                po.basepath # prefetch now; fails when repos are closed
             remote_pkgs.append(po)
             remote_size += po.size
             
@@ -2249,6 +2253,11 @@ much more problems).
             # way to save this, report the error and return
             if (self.conf.cache or repo_cached) and errors:
                 return errors
+        if downloadonly:
+            # close DBs, unlock
+            self.repos.close()
+            self.closeRpmDB()
+            self.doUnlock()
 
         remote_pkgs.sort(mediasort)
         #  This is kind of a hack and does nothing in non-Fedora versions,
@@ -2318,7 +2327,21 @@ much more problems).
         if callback_total is not None and not errors:
             callback_total(remote_pkgs, remote_size, beg_download)
 
-        self.plugins.run('postdownload', pkglist=pkglist, errors=errors)
+        if downloadonly:
+            for po in remote_pkgs:
+                rpmfile = po.localpath.rsplit('.', 2)[0]
+                if po in errors:
+                    # we may throw away partial file here- but we don't lock,
+                    # so can't rename tempfile to rpmfile safely
+                    misc.unlink_f(po.localpath)
+                if po not in errors:
+                    # verifyPkg() didn't complain, so (potentially)
+                    # overwriting another copy should not be a problem
+                    os.rename(po.localpath, rpmfile)
+                po.localpath = rpmfile
+        else:
+            # XXX: Run unlocked?  Skip this for now..
+            self.plugins.run('postdownload', pkglist=pkglist, errors=errors)
 
         # Close curl object after we've downloaded everything.
         if hasattr(urlgrabber.grabber, 'reset_curl_obj'):
-- 
1.7.4.4



More information about the Yum-devel mailing list