From 782e662a137e6985dafe700fe812b2f7033dc05c Mon Sep 17 00:00:00 2001
From: Darko Poljak <foss@ungleich.com>
Date: Thu, 2 Nov 2017 17:54:14 +0100
Subject: [PATCH] Remove invalid type link from runtime conf dir at proper
 time.

---
 cdist/core/cdist_type.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/cdist/core/cdist_type.py b/cdist/core/cdist_type.py
index ed386631..42533a4d 100644
--- a/cdist/core/cdist_type.py
+++ b/cdist/core/cdist_type.py
@@ -55,7 +55,6 @@ class CdistType(object):
         self.path = self.name
         self.absolute_path = os.path.join(self.base_path, self.path)
         if not os.path.isdir(self.absolute_path):
-            os.remove(self.absolute_path)
             raise InvalidTypeError(self.name, self.path, self.absolute_path)
         self.manifest_path = os.path.join(self.name, "manifest")
         self.explorer_path = os.path.join(self.name, "explorer")
@@ -83,6 +82,9 @@ class CdistType(object):
             except InvalidTypeError as e:
                 # ignore invalid type, log warning and continue
                 cls.log.warning(e)
+                # remove invalid from runtime conf dir
+                absolute_path = os.path.join(base_path, name)
+                os.remove(absolute_path)
 
     @classmethod
     def list_type_names(cls, base_path):