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