Skip to content

Commit 5a38a6a

Browse files
committed
Store buildinfo and buildconfig files in GitStore's cache instead directly in the repo
1 parent 663bcda commit 5a38a6a

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

osc/build.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,10 @@ def main(apiurl, store, opts, argv):
941941
bc_file = None
942942
bi_filename = '_buildinfo-%s-%s.xml' % (repo, arch)
943943
bc_filename = '_buildconfig-%s-%s' % (repo, arch)
944-
if store is not None and store.is_package and os.access(core.store, os.W_OK):
944+
if store is not None and hasattr(store, "cache_get_path"):
945+
bi_filename = store.cache_get_path(bi_filename, makedirs=True)
946+
bc_filename = store.cache_get_path(bc_filename, makedirs=True)
947+
elif store is not None and store.is_package and os.access(core.store, os.W_OK):
945948
bi_filename = os.path.join(os.getcwd(), core.store, bi_filename)
946949
bc_filename = os.path.join(os.getcwd(), core.store, bc_filename)
947950
elif not os.access('.', os.W_OK):

osc/git_scm/store.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,17 @@ def cache_list_files(self, *, pattern: Optional[str] = None, branch: Optional[st
328328
files = [i for i in files if fnmatch.fnmatch(i, pattern)]
329329
return files
330330

331-
def cache_read_file(self, filename: str, *, branch: Optional[str] = None) -> Optional[bytes]:
332-
assert "/" not in filename
331+
def cache_get_path(self, filename: str, *, branch: Optional[str] = None, makedirs: bool = False) -> str:
332+
if "/" in filename:
333+
raise ValueError(f"Filename must not contain path: {filename}")
333334
branch = branch or self._git.current_branch
334335
path = self._get_path(["cache", filename], branch=branch)
336+
if makedirs:
337+
os.makedirs(os.path.dirname(path), exist_ok=True)
338+
return path
339+
340+
def cache_read_file(self, filename: str, *, branch: Optional[str] = None) -> Optional[bytes]:
341+
path = self.cache_get_path(filename, branch=branch)
335342
with self._lock():
336343
try:
337344
with open(path, "rb") as f:
@@ -340,9 +347,7 @@ def cache_read_file(self, filename: str, *, branch: Optional[str] = None) -> Opt
340347
return None
341348

342349
def cache_write_file(self, filename: str, data: bytes, *, branch: Optional[str] = None):
343-
assert "/" not in filename
344-
branch = branch or self._git.current_branch
345-
path = self._get_path(["cache", filename], branch=branch)
350+
path = self.cache_get_path(filename, branch=branch)
346351
with self._lock():
347352
os.makedirs(os.path.dirname(path), exist_ok=True)
348353
with open(path, "wb") as f:
@@ -352,9 +357,11 @@ def cache_delete_files(self, filenames: List[str], *, branch: Optional[str] = No
352357
branch = branch or self._git.current_branch
353358
with self._lock():
354359
for filename in filenames:
355-
assert "/" not in filename
356-
path = self._get_path(["cache", filename], branch=branch)
357-
os.unlink(path)
360+
path = self.cache_get_path(filename, branch=branch)
361+
try:
362+
os.unlink(path)
363+
except FileNotFoundError:
364+
pass
358365

359366
# LAST BUILDROOT
360367

0 commit comments

Comments
 (0)