From fb3c4fc80ab80d7c066746b0656f571f0cb46840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Fri, 17 Aug 2018 00:19:20 +0100 Subject: [PATCH] nur combine: delete old content before copying new --- nur/combine.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nur/combine.py b/nur/combine.py index a9e9e5e74..d48bd2d80 100644 --- a/nur/combine.py +++ b/nur/combine.py @@ -2,6 +2,7 @@ import logging import os import shutil import subprocess +from tempfile import TemporaryDirectory from argparse import Namespace from distutils.dir_util import copy_tree from pathlib import Path @@ -44,12 +45,22 @@ def commit_files(files: List[str], message: str) -> None: def commit_repo(repo: Repo, message: str, path: Path) -> Repo: - repo_path = str(path.joinpath(repo.name).resolve()) + repo_path = path.joinpath(repo.name).resolve() - copy_tree(repo_source(repo.name), repo_path) + tmp: Optional[TemporaryDirectory] = TemporaryDirectory(prefix=str(repo_path.parent)) + assert tmp is not None + + try: + copy_tree(repo_source(repo.name), tmp.name) + shutil.rmtree(repo_path, ignore_errors=True) + os.rename(tmp.name, repo_path) + tmp = None + finally: + if tmp is not None: + tmp.cleanup() with chdir(str(path)): - commit_files([repo_path], message) + commit_files([str(repo_path)], message) return repo