Blame SOURCES/0009-yum.misc.decompress-to-handle-uncompressed-files-RhBug-1895059.patch

5dd470
From de8bbccc4e035a9a9b5baa3aeb0dbf0cb12f1fe2 Mon Sep 17 00:00:00 2001
5dd470
From: Marek Blaha <mblaha@redhat.com>
5dd470
Date: Wed, 9 Dec 2020 13:45:46 +0100
5dd470
Subject: [PATCH 1/1] yum.misc.decompress() to handle uncompressed files
5dd470
 (RhBug:1895059)
5dd470
5dd470
The underlying libdnf function is capable to handle even uncompressed
5dd470
files - so now uncompressed files are just copied to the destination.
5dd470
Also unused fn_only parameter of the function was removed.
5dd470
5dd470
This fixes issue with "reposync -m" command when the group metadata file
5dd470
in the repository is a plain xml file (not compressed).
5dd470
5dd470
https://bugzilla.redhat.com/show_bug.cgi?id=1895059
5dd470
---
5dd470
 dnf/yum/misc.py | 60 +++++++++++++++++++++++++++----------------------
5dd470
 1 file changed, 33 insertions(+), 27 deletions(-)
5dd470
5dd470
diff --git a/dnf/yum/misc.py b/dnf/yum/misc.py
5dd470
index 0f922350..3e3905fe 100644
5dd470
--- a/dnf/yum/misc.py
5dd470
+++ b/dnf/yum/misc.py
5dd470
@@ -386,34 +386,39 @@ def getloginuid():
5dd470
         _cached_getloginuid = _getloginuid()
5dd470
     return _cached_getloginuid
5dd470
 
5dd470
-def decompress(filename, dest=None, fn_only=False, check_timestamps=False):
5dd470
-    """take a filename and decompress it into the same relative location.
5dd470
-       if the file is not compressed just return the file"""
5dd470
-
5dd470
-    ztype = None
5dd470
-    out = filename  # If the file is not compressed, it returns the same file
5dd470
 
5dd470
-    dot_pos = filename.rfind('.')
5dd470
-    if dot_pos > 0:
5dd470
-        ext = filename[dot_pos:]
5dd470
-        if ext in ('.zck', '.xz', '.bz2', '.gz'):
5dd470
-            ztype = ext
5dd470
-            out = dest if dest else filename[:dot_pos]
5dd470
-
5dd470
-    if ztype and not fn_only:
5dd470
-        if check_timestamps:
5dd470
-            fi = stat_f(filename)
5dd470
-            fo = stat_f(out)
5dd470
-            if fi and fo and fo.st_mtime == fi.st_mtime:
5dd470
-                return out
5dd470
+def decompress(filename, dest=None, check_timestamps=False):
5dd470
+    """take a filename and decompress it into the same relative location.
5dd470
+       When the compression type is not recognized (or file is not compressed),
5dd470
+       the content of the file is copied to the destination"""
5dd470
+
5dd470
+    if dest:
5dd470
+        out = dest
5dd470
+    else:
5dd470
+        out = None
5dd470
+        dot_pos = filename.rfind('.')
5dd470
+        if dot_pos > 0:
5dd470
+            ext = filename[dot_pos:]
5dd470
+            if ext in ('.zck', '.xz', '.bz2', '.gz', '.lzma', '.zst'):
5dd470
+                out = filename[:dot_pos]
5dd470
+        if out is None:
5dd470
+            raise dnf.exceptions.MiscError("Could not determine destination filename")
5dd470
+
5dd470
+    if check_timestamps:
5dd470
+        fi = stat_f(filename)
5dd470
+        fo = stat_f(out)
5dd470
+        if fi and fo and fo.st_mtime == fi.st_mtime:
5dd470
+            return out
5dd470
 
5dd470
-        try:
5dd470
-            libdnf.utils.decompress(filename, out, 0o644, ztype)
5dd470
-        except RuntimeError as e:
5dd470
-            raise dnf.exceptions.MiscError(str(e))
5dd470
+    try:
5dd470
+        # libdnf.utils.decompress either decompress file to the destination or
5dd470
+        # copy the content if the compression type is not recognized
5dd470
+        libdnf.utils.decompress(filename, out, 0o644)
5dd470
+    except RuntimeError as e:
5dd470
+        raise dnf.exceptions.MiscError(str(e))
5dd470
 
5dd470
-        if check_timestamps and fi:
5dd470
-            os.utime(out, (fi.st_mtime, fi.st_mtime))
5dd470
+    if check_timestamps and fi:
5dd470
+        os.utime(out, (fi.st_mtime, fi.st_mtime))
5dd470
 
5dd470
     return out
5dd470
 
5dd470
@@ -424,13 +429,14 @@ def calculate_repo_gen_dest(filename, generated_name):
5dd470
         os.makedirs(dest, mode=0o755)
5dd470
     return dest + '/' + generated_name
5dd470
 
5dd470
-def repo_gen_decompress(filename, generated_name, cached=False):
5dd470
+
5dd470
+def repo_gen_decompress(filename, generated_name):
5dd470
     """ This is a wrapper around decompress, where we work out a cached
5dd470
         generated name, and use check_timestamps. filename _must_ be from
5dd470
         a repo. and generated_name is the type of the file. """
5dd470
 
5dd470
     dest = calculate_repo_gen_dest(filename, generated_name)
5dd470
-    return decompress(filename, dest=dest, check_timestamps=True, fn_only=cached)
5dd470
+    return decompress(filename, dest=dest, check_timestamps=True)
5dd470
 
5dd470
 def read_in_items_from_dot_dir(thisglob, line_as_list=True):
5dd470
     """ Takes a glob of a dir (like /etc/foo.d/\\*.foo) returns a list of all
5dd470
-- 
5dd470
2.26.2
5dd470