diff --git a/cli/copr_cli/main.py b/cli/copr_cli/main.py index a7df8fc36..5199b8366 100644 --- a/cli/copr_cli/main.py +++ b/cli/copr_cli/main.py @@ -327,10 +327,7 @@ def action_build(self, args): self.client.build_proxy.check_before_build( ownername=username, projectname=projectname, - # documentation says user can create directory with copr build, but - # /build/check-before-build endpoint checks for presence of this - # dirname even before creating it in this check. - project_dirname=None, + project_dirname=project_dirname, buildopts=buildopts, ) diff --git a/frontend/coprs_frontend/coprs/logic/coprs_logic.py b/frontend/coprs_frontend/coprs/logic/coprs_logic.py index 67e0198f0..d7eb73472 100644 --- a/frontend/coprs_frontend/coprs/logic/coprs_logic.py +++ b/frontend/coprs_frontend/coprs/logic/coprs_logic.py @@ -664,16 +664,10 @@ def _valid_custom_dir_suffix(copr, dirname): return all([c.isnumeric() for c in parts[2]]) @classmethod - def get_or_create(cls, copr, dirname): + def validate(cls, copr, dirname): """ - Create a CoprDir on-demand, e.g. before pull-request builds is - submitted. We don't create the "main" CoprDirs here (those are created - when a new project is created. + Raise exception if dirname is invalid for copr. """ - copr_dir = cls.get_by_copr_or_none(copr, dirname) - if copr_dir: - return copr_dir - if not dirname.startswith(copr.name+':'): raise MalformedArgumentException( "Copr dirname must start with '{}:' prefix".format( @@ -691,6 +685,22 @@ def get_or_create(cls, copr, dirname): f"Wrong directory '{dirname}' specified. Directory name can " "consist of alpha-numeric strings separated by colons.") + @classmethod + def get_or_validate(cls, copr, dirname): + if copr_dir := cls.get_by_copr_or_none(copr, dirname): + return copr_dir + cls.validate(copr, dirname) + return None + + @classmethod + def get_or_create(cls, copr, dirname): + """ + Create a CoprDir on-demand, e.g. before pull-request builds is + submitted. We don't create the "main" CoprDirs here (those are created + when a new project is created. + """ + if copr_dir := cls.get_or_validate(copr, dirname): + return copr_dir try: copr_dir = models.CoprDir(name=dirname, copr=copr, main=False) db.session.add(copr_dir) diff --git a/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_builds.py b/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_builds.py index 665307531..8e5c365b4 100644 --- a/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_builds.py +++ b/frontend/coprs_frontend/coprs/views/apiv3_ns/apiv3_builds.py @@ -229,7 +229,7 @@ def check_before_build(): # Raises an exception if CoprDir doesn't exist if data.get("project_dirname"): - CoprDirsLogic.get_by_copr(copr, data["project_dirname"]) + CoprDirsLogic.get_or_validate(copr, data["project_dirname"]) # Permissions check if not flask.g.user.can_build_in(copr):