Skip to content

Commit

Permalink
Safe cloning
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt-schesch committed May 5, 2024
1 parent faf5837 commit ff378ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
5 changes: 2 additions & 3 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ fi
mkdir -p "$OUT_DIR"

# Delete all locks in cache
if [ -d "$CACHE_DIR" ]; then
find "$CACHE_DIR" -name "*.lock" -delete
fi
find "$CACHE_DIR" -name "*.lock" -delete
find "repos" -name "*.lock" -delete

# Delete .workdir
rm -rf .workdir
Expand Down
26 changes: 11 additions & 15 deletions src/python/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
set_in_cache,
lookup_in_cache,
)
import fasteners
import git.repo
from variables import (
REPOS_PATH,
Expand Down Expand Up @@ -209,21 +210,16 @@ def __init__( # pylint: disable=too-many-arguments

def clone_repo(self) -> None:
"""Clones the repository."""
if self.repo_path.exists():
return
print(
"Cloning",
self.repo_slug,
"to",
self.repo_path,
"because:",
self.repo_path.exists(),
)
try:
clone_repo(self.repo_slug, self.repo_path)
except Exception as e:
logger.error("Exception during cloning:\n", e)
raise
lock_path = REPOS_PATH / "locks" / self.repo_slug
lock = fasteners.InterProcessLock(lock_path)
with lock:
if self.repo_path.exists():
return
try:
clone_repo(self.repo_slug, self.repo_path)
except Exception as e:
logger.error("Exception during cloning:\n", e)
raise
if not self.repo_path.exists():
logger.error(
f"Repo {self.repo_slug} does not exist after cloning {self.repo_path}"
Expand Down

0 comments on commit ff378ed

Please sign in to comment.