Skip to content

Commit

Permalink
docs: GitStorageBackend docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
renatav committed Dec 4, 2024
1 parent 7db3588 commit ada9ead
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions taf/tuf/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ def is_subpath(path, potential_subpath):


def find_git_repository(inner_path):
"""
Instantiates a git repository based on a path
that is expected to be inside that repository.
Enables smoother integration with TUF's default
FilesystemBackend implementation
"""
for path in list(git_repos_cache.keys()):
if is_subpath(inner_path, path):
return git_repos_cache[path]
Expand All @@ -51,6 +57,12 @@ def find_git_repository(inner_path):


class GitStorageBackend(FilesystemBackend):
"""
Storage backend implemnantation that loads data
from a specific commit, if it is specified,
or from the filesystem, if the commit is None
Extends TUF's FilesystemBackend.
"""

commit: Optional[str] = None

Expand Down Expand Up @@ -91,11 +103,9 @@ def getsize(self, filepath: str) -> int:
raise StorageError(e)

def put(self, fileobj: IO, filepath: str, restrict: Optional[bool] = False) -> None:
repo_path = pygit2.discover_repository(filepath)
if repo_path:
repo = find_git_repository(filepath)
if repo.is_bare_repository:
raise TAFError(
f"Cannot write to {filepath}. Repository is a bare repository"
)
repo = find_git_repository(filepath)
if repo.is_bare_repository:
raise TAFError(
f"Cannot write to {filepath}. Repository is a bare repository"
)
super().put(fileobj, filepath, restrict)

0 comments on commit ada9ead

Please sign in to comment.