From 756ade1c654664bc8888d1534642f1d8a3874756 Mon Sep 17 00:00:00 2001 From: wcbing Date: Mon, 3 Nov 2025 20:16:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=20Packages=20?= =?UTF-8?q?=E5=88=86=E5=89=B2=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- merge-apt-repo.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/merge-apt-repo.py b/merge-apt-repo.py index fccc8ca..4e8a973 100755 --- a/merge-apt-repo.py +++ b/merge-apt-repo.py @@ -76,10 +76,6 @@ def get_remote_packages(repo_url: str, file_path: str) -> bytes: else: # Packages content = response.content - # complete the two newlines if the ending is less than two newlines - # 结尾不足两个换行符的话,补全两个换行符 - if not content.endswith(b"\n\n"): - content += b"\n" return content.replace(b"Filename: ", f"Filename: {repo_url}".encode()) except Exception as e: logging.error(f"Error fetching packages: {e}") @@ -91,10 +87,15 @@ def split_latest(packages_file_content: bytes): split the information of each packet, deduplication and store the latest in infoList 将每个包的信息分割开,去重并将最新的存放到 infoList 中 """ - packages_file_content = re.sub( - rb"^Package: ", b"{{start}}Package: ", packages_file_content, flags=re.MULTILINE - ) - package_list = packages_file_content.split(b"{{start}}")[1:] + # Remove trailing empty lines first + packages_file_content = packages_file_content.rstrip(b"\n\r\t ") + + # split on two or more consecutive blank lines + package_list = [ + part + b"\n\n" + for part in re.split(rb"(?:\r?\n){2,}", packages_file_content) + if part.strip() + ] find_name = re.compile(rb"Package: (.+)") find_arch = re.compile(rb"Architecture: (.+)")