richardphibel / rpms / dnf

Forked from rpms/dnf 2 years ago
Clone
Blob Blame History Raw
From de8bbccc4e035a9a9b5baa3aeb0dbf0cb12f1fe2 Mon Sep 17 00:00:00 2001
From: Marek Blaha <mblaha@redhat.com>
Date: Wed, 9 Dec 2020 13:45:46 +0100
Subject: [PATCH 1/1] yum.misc.decompress() to handle uncompressed files
 (RhBug:1895059)

The underlying libdnf function is capable to handle even uncompressed
files - so now uncompressed files are just copied to the destination.
Also unused fn_only parameter of the function was removed.

This fixes issue with "reposync -m" command when the group metadata file
in the repository is a plain xml file (not compressed).

https://bugzilla.redhat.com/show_bug.cgi?id=1895059
---
 dnf/yum/misc.py | 60 +++++++++++++++++++++++++++----------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/dnf/yum/misc.py b/dnf/yum/misc.py
index 0f922350..3e3905fe 100644
--- a/dnf/yum/misc.py
+++ b/dnf/yum/misc.py
@@ -386,34 +386,39 @@ def getloginuid():
         _cached_getloginuid = _getloginuid()
     return _cached_getloginuid
 
-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"""
-
-    ztype = None
-    out = filename  # If the file is not compressed, it returns the same file
 
-    dot_pos = filename.rfind('.')
-    if dot_pos > 0:
-        ext = filename[dot_pos:]
-        if ext in ('.zck', '.xz', '.bz2', '.gz'):
-            ztype = ext
-            out = dest if dest else filename[:dot_pos]
-
-    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:
-                return out
+def decompress(filename, dest=None, check_timestamps=False):
+    """take a filename and decompress it into the same relative location.
+       When the compression type is not recognized (or file is not compressed),
+       the content of the file is copied to the destination"""
+
+    if dest:
+        out = dest
+    else:
+        out = None
+        dot_pos = filename.rfind('.')
+        if dot_pos > 0:
+            ext = filename[dot_pos:]
+            if ext in ('.zck', '.xz', '.bz2', '.gz', '.lzma', '.zst'):
+                out = filename[:dot_pos]
+        if out is None:
+            raise dnf.exceptions.MiscError("Could not determine destination filename")
+
+    if check_timestamps:
+        fi = stat_f(filename)
+        fo = stat_f(out)
+        if fi and fo and fo.st_mtime == fi.st_mtime:
+            return out
 
-        try:
-            libdnf.utils.decompress(filename, out, 0o644, ztype)
-        except RuntimeError as e:
-            raise dnf.exceptions.MiscError(str(e))
+    try:
+        # libdnf.utils.decompress either decompress file to the destination or
+        # copy the content if the compression type is not recognized
+        libdnf.utils.decompress(filename, out, 0o644)
+    except RuntimeError as e:
+        raise dnf.exceptions.MiscError(str(e))
 
-        if check_timestamps and fi:
-            os.utime(out, (fi.st_mtime, fi.st_mtime))
+    if check_timestamps and fi:
+        os.utime(out, (fi.st_mtime, fi.st_mtime))
 
     return out
 
@@ -424,13 +429,14 @@ def calculate_repo_gen_dest(filename, generated_name):
         os.makedirs(dest, mode=0o755)
     return dest + '/' + generated_name
 
-def repo_gen_decompress(filename, generated_name, cached=False):
+
+def repo_gen_decompress(filename, generated_name):
     """ This is a wrapper around decompress, where we work out a cached
         generated name, and use check_timestamps. filename _must_ be from
         a repo. and generated_name is the type of the file. """
 
     dest = calculate_repo_gen_dest(filename, generated_name)
-    return decompress(filename, dest=dest, check_timestamps=True, fn_only=cached)
+    return decompress(filename, dest=dest, check_timestamps=True)
 
 def read_in_items_from_dot_dir(thisglob, line_as_list=True):
     """ Takes a glob of a dir (like /etc/foo.d/\\*.foo) returns a list of all
-- 
2.26.2