[Yum-devel] [PATCH 1/2] refactor misc.decompress()

Zdeněk Pavlas zpavlas at redhat.com
Thu May 31 10:34:24 UTC 2012


---
 yum/misc.py |   54 +++++++++++++++++++-----------------------------------
 1 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/yum/misc.py b/yum/misc.py
index 55c433a..a6a501c 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -1106,43 +1106,27 @@ def decompress(filename, dest=None, fn_only=False, check_timestamps=False):
     """take a filename and decompress it into the same relative location.
        if the file is not compressed just return the file"""
     
-    out = dest
-    if not dest:
-        out = filename
-        
-    if filename.endswith('.gz'):
-        ztype='gz'
-        if not dest: 
-            out = filename.replace('.gz', '')
-
-    elif filename.endswith('.bz') or filename.endswith('.bz2'):
-        ztype='bz2'
-        if not dest:
-            if filename.endswith('.bz'):
-                out = filename.replace('.bz','')
-            else:
-                out = filename.replace('.bz2', '')
-    
-    elif filename.endswith('.xz'):
-        ztype='xz'
-        if not dest:
-            out = filename.replace('.xz', '')
-        
-    else:
-        out = filename # returning the same file since it is not compressed
-        ztype = None
-    
-    if ztype and not fn_only:
-        if check_timestamps:
-            fi = stat_f(filename)
-            fo = stat_f(out)
-            if fi and fo and fo.st_mtime == fi.st_mtime:
+    out, ztype = filename.rsplit('.', 1)
+    if ztype == 'bz':
+        ztype = 'bz2'
+    elif ztype not in ('gz', 'bz2', 'xz'):
+        return filename # not compressed
+    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
 
-        _decompress_chunked(filename, out, ztype)
-        if check_timestamps and fi:
-            os.utime(out, (fi.st_mtime, fi.st_mtime))
-        
+    _decompress_chunked(filename, out, ztype)
+    if check_timestamps and fi:
+        os.utime(out, (fi.st_mtime, fi.st_mtime))
     return out
     
 def repo_gen_decompress(filename, generated_name, cached=False):
-- 
1.7.4.4



More information about the Yum-devel mailing list