Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Patch Provider pulling in parallel #835

Merged
merged 9 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions varats-core/varats/provider/patch/patch_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from varats.project.project_util import get_local_project_git_path
from varats.provider.provider import Provider, ProviderType
from varats.utils.filesystem_util import lock_file
from varats.utils.git_commands import pull_current_branch, fetch_repository
from varats.utils.git_util import (
CommitHash,
Expand Down Expand Up @@ -237,12 +238,10 @@ class PatchProvider(Provider):
def __init__(self, project: tp.Type[Project]):
super().__init__(project)

# BB only performs a fetch so our repo might be out of date
pull_current_branch(self._get_patches_repository_path())
self._update_local_patches_repo()
repo_path = self._get_patches_repository_path()

patches_project_dir = Path(
self._get_patches_repository_path() / self.project.NAME
)
patches_project_dir = repo_path / self.project.NAME

if not patches_project_dir.is_dir():
warnings.warn(
Expand Down Expand Up @@ -316,6 +315,12 @@ def create_default_provider(

@classmethod
def _get_patches_repository_path(cls) -> Path:
cls.patches_source.fetch()

return Path(target_prefix()) / cls.patches_source.local

@classmethod
def _update_local_patches_repo(cls):
lock_path = Path(target_prefix()) / "patch_provider.lock"

with lock_file(lock_path):
cls.patches_source.fetch()
pull_current_branch(cls._get_patches_repository_path())
16 changes: 15 additions & 1 deletion varats-core/varats/utils/filesystem_util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""Utility functions for handling filesystem related tasks."""

import fcntl
import os.path
import typing as tp
from contextlib import contextmanager
from pathlib import Path


Expand All @@ -13,3 +15,15 @@ def __init__(self, folder: tp.Union[Path, str]) -> None:
f"Folder: '{str(folder)}' should be created "
"but was already present."
)


@contextmanager
def lock_file(lock_path: Path, lock_mode: int = fcntl.LOCK_EX) -> tp.Generator:
LuAbelt marked this conversation as resolved.
Show resolved Hide resolved
open_mode = os.O_RDWR | os.O_CREAT | os.O_TRUNC
lock_fd = os.open(lock_path, open_mode)
try:
fcntl.flock(lock_fd, lock_mode)
yield
finally:
fcntl.flock(lock_fd, fcntl.LOCK_UN)
os.close(lock_fd)