packages/build: add_file_to_repo(): add remove_original=True parameter, clean up add_package_to_repo()

This commit is contained in:
InsanePrawn 2022-09-04 01:10:53 +02:00
parent 57fec8fd91
commit a2c8868d61

View file

@ -193,7 +193,7 @@ def generate_dependency_chain(package_repo: dict[str, Pkgbuild], to_build: Itera
return list([lvl for lvl in dep_levels[::-1] if lvl]) return list([lvl for lvl in dep_levels[::-1] if lvl])
def add_file_to_repo(file_path: str, repo_name: str, arch: Arch): def add_file_to_repo(file_path: str, repo_name: str, arch: Arch, remove_original: bool = True):
check_programs_wrap(['repo-add']) check_programs_wrap(['repo-add'])
repo_dir = os.path.join(config.get_package_dir(arch), repo_name) repo_dir = os.path.join(config.get_package_dir(arch), repo_name)
pacman_cache_dir = os.path.join(config.get_path('pacman'), arch) pacman_cache_dir = os.path.join(config.get_path('pacman'), arch)
@ -207,6 +207,7 @@ def add_file_to_repo(file_path: str, repo_name: str, arch: Arch):
file_path, file_path,
repo_dir, repo_dir,
) )
if remove_original:
remove_file(file_path) remove_file(file_path)
# clean up same name package from pacman cache # clean up same name package from pacman cache
@ -229,11 +230,7 @@ def add_file_to_repo(file_path: str, repo_name: str, arch: Arch):
if result.returncode != 0: if result.returncode != 0:
raise Exception(f'Failed add package {target_file} to repo {repo_name}') raise Exception(f'Failed add package {target_file} to repo {repo_name}')
for ext in ['db', 'files']: for ext in ['db', 'files']:
file = os.path.join(repo_dir, f'{repo_name}.{ext}') old = os.path.join(repo_dir, f'{repo_name}.{ext}.tar.xz.old')
if os.path.exists(file + '.tar.xz'):
remove_file(file)
shutil.copyfile(file + '.tar.xz', file)
old = file + '.tar.xz.old'
if os.path.exists(old): if os.path.exists(old):
remove_file(old) remove_file(old)
@ -252,9 +249,12 @@ def add_package_to_repo(package: Pkgbuild, arch: Arch):
files = [] files = []
for file in os.listdir(pkgbuild_dir): for file in os.listdir(pkgbuild_dir):
stripped_name = strip_compression_extension(file)
# Forced extension by makepkg.conf # Forced extension by makepkg.conf
if not stripped_name.endswith('.pkg.tar'): pkgext = '.pkg.tar'
if pkgext not in file:
continue
stripped_name = strip_compression_extension(file)
if not stripped_name.endswith(pkgext):
continue continue
repo_file = os.path.join(config.get_package_dir(arch), package.repo, file) repo_file = os.path.join(config.get_package_dir(arch), package.repo, file)
@ -262,13 +262,11 @@ def add_package_to_repo(package: Pkgbuild, arch: Arch):
add_file_to_repo(os.path.join(pkgbuild_dir, file), package.repo, arch) add_file_to_repo(os.path.join(pkgbuild_dir, file), package.repo, arch)
# copy any-arch packages to other repos as well # copy any-arch packages to other repos as well
if stripped_name.endswith('any.pkg.tar'): if stripped_name.endswith(f'-any{pkgext}'):
for repo_arch in ARCHES: for repo_arch in ARCHES:
if repo_arch == arch: if repo_arch == arch:
continue continue # done already
copy_target = os.path.join(config.get_package_dir(repo_arch), package.repo, file) add_file_to_repo(repo_file, package.repo, repo_arch, remove_original=False)
shutil.copy(repo_file, copy_target)
add_file_to_repo(copy_target, package.repo, repo_arch)
return files return files