From 6fda3bf8ea70d20acb2ffca00655af6c73dbd36b Mon Sep 17 00:00:00 2001
From: Seblu <sebastien.luttringer@smartjog.com>
Date: Wed, 24 Aug 2011 18:05:49 +0200
Subject: [PATCH] stricter check during image selection

---
 bin/is                       | 6 +++++-
 installsystems/repository.py | 3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/bin/is b/bin/is
index e872a6a..4ebd6b1 100755
--- a/bin/is
+++ b/bin/is
@@ -58,7 +58,11 @@ def select_image(name, repoman):
     if istools.isfile(name) and os.path.isfile(name):
         return PackageImage(name), None
     else:
-        (repo, image, version) = re.match("((\w+)/)?(\w+)(:v?(\d+))?", name).group(2,3,5)
+        x = re.match("^((\w+)/)?(\w+)(:v?(\d+))?$", name)
+        if x is None:
+            raise Exception("%s is not a valid image" % name)
+        (repo, image, version) = x.group(2,3,5)
+        debug("Selected image is %s v%s in %s" % (image, version, repo))
         if repo is None:
             return repoman.get(image, version)
         else:
diff --git a/installsystems/repository.py b/installsystems/repository.py
index a716b24..3e11c5f 100644
--- a/installsystems/repository.py
+++ b/installsystems/repository.py
@@ -266,6 +266,9 @@ class Repository(object):
         # is no version take the last
         if version is None:
             version = self.last(name)
+            if version < 0:
+                raise Exception("Unable to find last version of %s in %s" % (name,
+                                                                             self.config.name))
         # get file md5 from db
         r = self.db.ask("select md5 from image where name = ? and version = ? limit 1",
                         (name,version)).fetchone()
-- 
GitLab