fix: 修改 Packages 分割方式

This commit is contained in:
wcbing 2025-11-03 20:16:26 +08:00
parent 46aea61e9d
commit 756ade1c65

View File

@ -76,10 +76,6 @@ def get_remote_packages(repo_url: str, file_path: str) -> bytes:
else: # Packages else: # Packages
content = response.content 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()) return content.replace(b"Filename: ", f"Filename: {repo_url}".encode())
except Exception as e: except Exception as e:
logging.error(f"Error fetching packages: {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 split the information of each packet, deduplication and store the latest in infoList
将每个包的信息分割开去重并将最新的存放到 infoList 将每个包的信息分割开去重并将最新的存放到 infoList
""" """
packages_file_content = re.sub( # Remove trailing empty lines first
rb"^Package: ", b"{{start}}Package: ", packages_file_content, flags=re.MULTILINE packages_file_content = packages_file_content.rstrip(b"\n\r\t ")
)
package_list = packages_file_content.split(b"{{start}}")[1:] # 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_name = re.compile(rb"Package: (.+)")
find_arch = re.compile(rb"Architecture: (.+)") find_arch = re.compile(rb"Architecture: (.+)")