aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliot Smith <elliot.smith@intel.com>2016-04-19 17:28:41 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-19 21:11:25 +0100
commitcfc22d3a9e2434fb5b9001850c19617dda6d57aa (patch)
treec90c1e55c48bf901288b2d22993e27c92fde0df6
parent3036413000786499d38026ae0c16b916a10b7c65 (diff)
downloadopenembedded-core-contrib-cfc22d3a9e2434fb5b9001850c19617dda6d57aa.tar.gz
bitbake: toaster: only prevent duplicate custom image names within a project
We currently prevent the same name being used for multiple custom images, but make the check across all projects. This means that custom image names have to be unique across all projects in the Toaster installation. Modify how we validate the name of a custom image so that we only prevent duplication of custom image names within a project, while ensuring that the name of a custom image doesn't duplicate the name of a recipe which is not a custom image recipe. [YOCTO #9209] (Bitbake rev: 9abbb46e799c06757e03addd54e3f5d3c0fe2886) Signed-off-by: Elliot Smith <elliot.smith@intel.com> Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js8
-rwxr-xr-xbitbake/lib/toaster/toastergui/views.py33
2 files changed, 24 insertions, 17 deletions
diff --git a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
index 328997af3b..98e87f4a6b 100644
--- a/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
+++ b/bitbake/lib/toaster/toastergui/static/js/newcustomimage_modal.js
@@ -9,6 +9,8 @@ function newCustomImageModalInit(){
var nameInput = imgCustomModal.find('input');
var invalidMsg = "Image names cannot contain spaces or capital letters. The only allowed special character is dash (-).";
+ var duplicateImageMsg = "An image with this name already exists in this project.";
+ var duplicateRecipeMsg = "A non-image recipe with this name already exists.";
newCustomImgBtn.click(function(e){
e.preventDefault();
@@ -22,8 +24,10 @@ function newCustomImageModalInit(){
console.warn(ret.error);
if (ret.error === "invalid-name") {
showError(invalidMsg);
- } else if (ret.error === "already-exists") {
- showError("An image with this name already exists. Image names must be unique.");
+ } else if (ret.error === "image-already-exists") {
+ showError(duplicateImageMsg);
+ } else if (ret.error === "recipe-already-exists") {
+ showError(duplicateRecipeMsg);
}
} else {
imgCustomModal.modal('hide');
diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py
index a11c9da5f5..9744f4efaf 100755
--- a/bitbake/lib/toaster/toastergui/views.py
+++ b/bitbake/lib/toaster/toastergui/views.py
@@ -2409,21 +2409,24 @@ if True:
if re.search(r'[^a-z|0-9|-]', request.POST["name"]):
return {"error": "invalid-name"}
- # Are there any recipes with the name already?
- for existing_recipe in Recipe.objects.filter(
- name=request.POST["name"]):
- try:
- ci = CustomImageRecipe.objects.get(pk=existing_recipe.pk)
- if ci.project == params["project"]:
- return {"error": "already-exists" }
- else:
- # It is a CustomImageRecipe but not in our project
- # this is fine so
- continue
- except:
- # It isn't a CustomImageRecipe so is a recipe from
- # another source.
- return {"error": "already-exists" }
+ custom_images = CustomImageRecipe.objects.all()
+
+ # Are there any recipes with this name already in our project?
+ existing_image_recipes_in_project = custom_images.filter(
+ name=request.POST["name"], project=params["project"])
+
+ if existing_image_recipes_in_project.count() > 0:
+ return {"error": "image-already-exists"}
+
+ # Are there any recipes with this name which aren't custom
+ # image recipes?
+ custom_image_ids = custom_images.values_list('id', flat=True)
+ existing_non_image_recipes = Recipe.objects.filter(
+ Q(name=request.POST["name"]) & ~Q(pk__in=custom_image_ids)
+ )
+
+ if existing_non_image_recipes.count() > 0:
+ return {"error": "recipe-already-exists"}
# create layer 'Custom layer' and verion if needed
layer = Layer.objects.get_or_create(