Skip to content

Commit

Permalink
Clean up repo before publishing artifacts
Browse files Browse the repository at this point in the history
Make sure to clean up the repo, before publishing artifacts. Starting
from scratch is necessary if we want to avoid some edge cases that can
lead to a corrupted APT repo.

Refs freedomofpress#11
  • Loading branch information
apyrgio committed Dec 12, 2023
1 parent df4ce3f commit 2ef99e1
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tools/publish
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ found in each.
import argparse
import logging
import os
import shutil
import subprocess
import sys

Expand All @@ -19,6 +20,11 @@ REPO_ROOT = os.path.abspath(os.path.join(__file__, os.pardir, os.pardir))
REPROPRO_DIR_DEFAULT = os.path.join(REPO_ROOT, "repo")
REPREPRO_DIR = os.environ.get("REPREPRO_BASE_DIR", REPROPRO_DIR_DEFAULT)
REPREPRO_PUBLIC_DIR = os.path.join(REPREPRO_DIR, "public")
REPREPRO_CLEANUP_DIRS = [
os.path.join(REPREPRO_DIR, "db"),
os.path.join(REPREPRO_PUBLIC_DIR, "pool"),
os.path.join(REPREPRO_PUBLIC_DIR, "dists"),
]

REPO_DIRS = [
"dangerzone",
Expand Down Expand Up @@ -92,6 +98,15 @@ def validate_repo():
logger.info("Successfully validated repo")


def cleanup_repo():
"""
Clean up previously created repo data
"""
logger.info("Cleaning up repo")
for d in REPREPRO_CLEANUP_DIRS:
shutil.rmtree(d, ignore_errors=True)


def get_release_files():
"""
Find all Release files, to facilitate generating a detached
Expand Down Expand Up @@ -132,6 +147,13 @@ def parse_args():
"--distros", required=False, nargs="+",
help="Operate on a set of specific distros (default: all)"
)
parser.add_argument(
"--dirty", default=False, action="store_true",
help=(
"DANGEROUS! Do not clean the APT db before publishing packages."
" See issue #11 on why this is important"
)
)
parser.add_argument(
"--TEST-no-validate", default=False, action="store_true",
help=(
Expand Down Expand Up @@ -177,6 +199,16 @@ def main():
else:
validate_repo()

if args.distros and not args.dirty:
logger.error("You must specify --dirty, if you want to operate only"
" on a specific set of distros")
return 1

if args.dirty:
logger.warning("Skipping repo cleanup")
else:
cleanup_repo()

for repo in REPO_DIRS:
publish_packages(repo, distros=args.distros)

Expand Down

0 comments on commit 2ef99e1

Please sign in to comment.