Skip to content

Commit

Permalink
Fail when git repository contains files supposed to be generated
Browse files Browse the repository at this point in the history
boo#1230469
  • Loading branch information
adrianschroeter committed Nov 11, 2024
1 parent 3709a0d commit 9afec06
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions obs_scm_bridge
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ class ObsGit(object):
line = self.run_cmd(cmd, cwd=outdir, fatal="git rev-parse")
tstamp = line.rstrip()
infofile = os.path.join(outdir, '_scmsync.obsinfo')
with open(infofile, "w") as obsinfo:
if os.path.exists(infofile):
logging.error("ERROR: The _scmsync.obsinfo file must not be part of the git repository.")
sys.exit(1)
with open(infofile, 'x') as obsinfo:
obsinfo.write("mtime: " + tstamp + "\n")
obsinfo.write("commit: " + commit + "\n")
if self.scmtoolurl:
Expand Down Expand Up @@ -305,15 +308,15 @@ class ObsGit(object):
def cpio_directory(self, directory: str) -> None:
logging.info("create archivefile for %s", directory)
cmd = [ download_assets, '--create-cpio', '--', directory ]
with open(directory + '.obscpio', 'w') as archivefile:
with open(directory + '.obscpio', 'x') as archivefile:
self.run_cmd(cmd, stdout=archivefile, fatal="cpio creation")

def cpio_specials(self, specials: List[str]) -> None:
if not specials:
return
logging.info("create archivefile for specials")
cmd = [ download_assets, '--create-cpio', '--', '.' ] + specials
with open('build.specials.obscpio', 'w') as archivefile:
with open('build.specials.obscpio', 'x') as archivefile:
self.run_cmd(cmd, stdout=archivefile, fatal="cpio creation")

def cpio_directories(self) -> None:
Expand Down Expand Up @@ -382,7 +385,10 @@ class ObsGit(object):
def write_info_file(self, filename: str, info: str) -> None:
if not filename.startswith("/"):
filename = self.outdir + "/" + filename
with open(filename, 'w') as infofile:
if os.path.exists(filename):
logging.error(f"ERROR: The {filename} file must not be part of the git repository.")
sys.exit(1)
with open(filename, 'x') as infofile:
infofile.write(info + '\n')

def add_service_info(self) -> None:
Expand All @@ -402,21 +408,33 @@ class ObsGit(object):
return
if projectscmsync:
projecturlxml=f"""\n <url>{escape(projectscmsync)}</url>"""
with open(f"{self.outdir}/{name}.xml", 'w') as xmlfile:
filename = f"{self.outdir}/{name}.xml"
if os.path.exists(filename):
logging.error(f"ERROR: The {name}.xml file must not be part of the git repository.")
sys.exit(1)
with open(filename, 'x') as xmlfile:
xmlfile.write(f"""<package name="{escape(name)}">""")
if self.enforce_bcntsynctag:
xmlfile.write(f"""<bcntsynctag>{escape(name)}</bcntsynctag>{projecturlxml}""")
xmlfile.write(f"""<scmsync>{escape(url)}</scmsync>
</package>\n""")

def write_package_xml_local_link(self, target: str, name: str) -> None:
with open(f"{self.outdir}/{name}.xml", 'w') as xmlfile:
filename = f"{self.outdir}/{name}.xml"
if os.path.exists(filename):
logging.error(f"ERROR: The {name}.xml file must not be part of the git repository.")
sys.exit(1)
with open(filename, 'x') as xmlfile:
xmlfile.write(f"""<package name="{escape(name)}">""")
if self.enforce_bcntsynctag:
xmlfile.write(f"""<bcntsynctag>{escape(name)}</bcntsynctag>{projecturlxml}""")
xmlfile.write(f"""</package>""")
self.export_files.add(name + ".xml")
with open(f"{self.outdir}/{name}.link", 'w') as linkfile:
filename = f"{self.outdir}/{name}.link"
if os.path.exists(filename):
logging.error(f"ERROR: The {name}.link file must not be part of the git repository.")
sys.exit(1)
with open(filename, 'x') as linkfile:
linkfile.write(f"""<link package="{escape(target)}" cicount="copy" />""")
self.export_files.add(name + ".link")

Expand Down

0 comments on commit 9afec06

Please sign in to comment.