Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/svn/utils.py
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | |||||
def init_svn_repo_from_dump( | def init_svn_repo_from_dump( | ||||
dump_path: str, | dump_path: str, | ||||
prefix: Optional[str] = None, | prefix: Optional[str] = None, | ||||
suffix: Optional[str] = None, | suffix: Optional[str] = None, | ||||
root_dir: str = "/tmp", | root_dir: str = "/tmp", | ||||
gzip: bool = False, | gzip: bool = False, | ||||
cleanup_dump: bool = True, | cleanup_dump: bool = True, | ||||
max_rev: int = -1, | |||||
) -> Tuple[str, str]: | ) -> Tuple[str, str]: | ||||
"""Given a path to a svn dump, initialize an svn repository with the content of said | """Given a path to a svn dump, initialize an svn repository with the content of said | ||||
dump. | dump. | ||||
Args: | Args: | ||||
dump_path: The dump to the path | dump_path: The dump to the path | ||||
prefix: optional prefix file name for the working directory | prefix: optional prefix file name for the working directory | ||||
suffix: optional suffix file name for the working directory | suffix: optional suffix file name for the working directory | ||||
Show All 29 Lines | try: | ||||
read_dump_cmd = ["cat", dump_path] | read_dump_cmd = ["cat", dump_path] | ||||
if gzip: | if gzip: | ||||
read_dump_cmd = ["gzip", "-dc", dump_path] | read_dump_cmd = ["gzip", "-dc", dump_path] | ||||
with Popen(read_dump_cmd, stdout=PIPE) as dump: | with Popen(read_dump_cmd, stdout=PIPE) as dump: | ||||
# load dump and bypass properties validation as Unicode decoding errors | # load dump and bypass properties validation as Unicode decoding errors | ||||
# are already handled in loader implementation (see _ra_codecs_error_handler | # are already handled in loader implementation (see _ra_codecs_error_handler | ||||
# in ra.py) | # in ra.py) | ||||
cmd = ["svnadmin", "load", "-q", "--bypass-prop-validation", repo_path] | cmd = ["svnadmin", "load", "-q", "--bypass-prop-validation"] | ||||
completed_process = run( | if max_rev > 0: | ||||
cmd, stdin=dump.stdout, capture_output=True, text=True | cmd.append(f"-r1:{max_rev}") | ||||
cmd.append(repo_path) | |||||
svnadmin_load = run(cmd, stdin=dump.stdout, capture_output=True, text=True) | |||||
if svnadmin_load.returncode != 0: | |||||
if max_rev > 0: | |||||
# if max_rev is specified, we might have a truncated dump due to | |||||
# an error when executing svnrdump, check if max_rev have been | |||||
# loaded and continue loading process if it is the case | |||||
svnadmin_info = run( | |||||
["svnadmin", "info", repo_path], capture_output=True, text=True | |||||
) | ) | ||||
if completed_process.returncode != 0: | if f"Revisions: {max_rev}\n" in svnadmin_info.stdout: | ||||
return temp_dir, repo_path | |||||
raise ValueError( | raise ValueError( | ||||
f"Failed to mount the svn dump for project {project_name}\n" | f"Failed to mount the svn dump for project {project_name}\n" | ||||
+ completed_process.stderr | + svnadmin_load.stderr | ||||
) | ) | ||||
return temp_dir, repo_path | return temp_dir, repo_path | ||||
except Exception as e: | except Exception as e: | ||||
shutil.rmtree(temp_dir) | shutil.rmtree(temp_dir) | ||||
raise e | raise e | ||||
finally: | finally: | ||||
if cleanup_dump: | if cleanup_dump: | ||||
try: | try: | ||||
▲ Show 20 Lines • Show All 200 Lines • Show Last 20 Lines |