[PATCH 1/2] downloadonly: rename or unlink .$pid.tmp files asap.
Zdenek Pavlas
zpavlas at redhat.com
Tue Jan 21 14:25:25 UTC 2014
Instead of renaming or unlinking all tmpfiles at once,
do this in the per-package callbacks.
---
yum/__init__.py | 22 ++++++----------------
yum/drpm.py | 6 +++++-
2 files changed, 11 insertions(+), 17 deletions(-)
diff --git a/yum/__init__.py b/yum/__init__.py
index c2432ed..5d55658 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2342,6 +2342,8 @@ much more problems).
errors = {}
def adderror(po, msg):
errors.setdefault(po, []).append(msg)
+ if po.localpath.endswith('.tmp'):
+ misc.unlink_f(po.localpath) # won't resume this..
# We close the history DB here because some plugins (presto) use
# threads. And sqlite really doesn't like threads. And while I don't
@@ -2434,6 +2436,10 @@ much more problems).
def checkfunc(obj, po=po):
self.verifyPkg(obj, po, 1)
+ if po.localpath.endswith('.tmp'):
+ rpmfile = po.localpath.rsplit('.', 2)[0]
+ os.rename(po.localpath, rpmfile)
+ po.localpath = rpmfile
local_size[0] += po.size
if hasattr(urlgrabber.progress, 'text_meter_total_size'):
urlgrabber.progress.text_meter_total_size(remote_size,
@@ -2479,22 +2485,6 @@ much more problems).
if hasattr(urlgrabber.progress, 'text_meter_total_size'):
urlgrabber.progress.text_meter_total_size(0)
- if downloadonly:
- for po in remote_pkgs:
- if not po.localpath.endswith('.tmp'):
- # file:// repos don't "download"
- continue
- 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)
- else:
- # verifyPkg() didn't complain, so (potentially)
- # overwriting another copy should not be a problem
- rpmfile = po.localpath.rsplit('.', 2)[0]
- os.rename(po.localpath, rpmfile)
- po.localpath = rpmfile
-
fatal = False
for po in errors:
if not isinstance(po, DeltaPackage):
diff --git a/yum/drpm.py b/yum/drpm.py
index 42bf70e..cc680cd 100644
--- a/yum/drpm.py
+++ b/yum/drpm.py
@@ -270,7 +270,11 @@ class DeltaInfo:
# done with drpm file, unlink when local
if po.localpath.startswith(po.repo.pkgdir):
os.unlink(po.localpath)
- po.localpath = po.rpm.localpath # for --downloadonly
+ # rename the rpm if --downloadonly
+ if po.rpm.localpath.endswith('.tmp'):
+ rpmfile = po.rpm.localpath.rsplit('.', 2)[0]
+ os.rename(po.rpm.localpath, rpmfile)
+ po.rpm.localpath = rpmfile
num += 1
# when blocking, one is enough
--
1.7.11.7
More information about the Yum-devel
mailing list