[Yum-devel] [PATCH 2/2] safer misc.decompress()
Zdeněk Pavlas
zpavlas at redhat.com
Thu May 31 10:34:25 UTC 2012
Clean up partially decompressed files. Also, return an error
when check_timestamps && fn_only && invalid out file exists.
This may fix weird bugs like BZ 825811 and BZ 826419.
(ctrl-c or no-space-left during decompression, then 'yum -C').
---
yum/misc.py | 18 ++++++++++++------
1 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/yum/misc.py b/yum/misc.py
index a6a501c..75efd83 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -1114,19 +1114,25 @@ def decompress(filename, dest=None, fn_only=False, check_timestamps=False):
if dest:
out = dest # override
- if fn_only:
- return out
-
if check_timestamps:
fi = stat_f(filename)
fo = stat_f(out)
if fi and fo:
if fo.st_mtime == fi.st_mtime:
return out
+ if fn_only:
+ # out exists but not valid
+ return None
+ if fn_only:
+ return out
- _decompress_chunked(filename, out, ztype)
- if check_timestamps and fi:
- os.utime(out, (fi.st_mtime, fi.st_mtime))
+ try:
+ _decompress_chunked(filename, out, ztype)
+ if check_timestamps and fi:
+ os.utime(out, (fi.st_mtime, fi.st_mtime))
+ except:
+ unlink_f(out)
+ raise
return out
def repo_gen_decompress(filename, generated_name, cached=False):
--
1.7.4.4
More information about the Yum-devel
mailing list