From 4ffc5255c6af03feb3123877c598e373a1904e15 Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Thu, 26 Mar 2020 12:36:40 +0200 Subject: [PATCH] io.schema: Prohibit directories in resource names --- kcidb/io/schema/v2.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/kcidb/io/schema/v2.py b/kcidb/io/schema/v2.py index b99ac378..87cdeddd 100644 --- a/kcidb/io/schema/v2.py +++ b/kcidb/io/schema/v2.py @@ -22,7 +22,9 @@ "type": "string", "description": "Resource name. Must be usable as a local file name for the " - "downloaded resource.", + "downloaded resource. Cannot be empty. Should not include " + "directories.", + "pattern": "^[^/]+$", }, "url": { "type": "string", @@ -537,6 +539,16 @@ def inherit(data): del obj[pair[0]] del obj[pair[1]] + # Replace slashes with underscores in resource names + for collection, prop_list in \ + dict(revisions=["patch_mboxes"], + builds=["input_files", "output_files"], + tests=["output_files"]).items(): + for obj in data.get(collection, []): + for prop in prop_list: + for resource in obj[prop]: + resource["name"] = resource["name"].replace("/", "_") + # Update version data['version'] = dict(major=JSON_VERSION_MAJOR, minor=JSON_VERSION_MINOR)