]> git.ipfire.org Git - nitsi.git/commitdiff
Improve handling of file which should be copied into the image
authorJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 6 Jun 2018 12:57:52 +0000 (14:57 +0200)
committerJonatan Schlag <jonatan.schlag@ipfire.org>
Wed, 6 Jun 2018 12:57:52 +0000 (14:57 +0200)
We now check if a the file or directory exists and throw an exception
when not. We also handle absolute and relativ paths in the right way.

Fixes: #11748
Fixes: #11747
Signed-off-by: Jonatan Schlag <jonatan.schlag@ipfire.org>
src/nitsi/test.py

index c49c0f395d21b16e132ffe2cfe9199e370cb7712..e1ae24cbd3cab719db7ffab0c3eceac06f790d2e 100755 (executable)
@@ -49,8 +49,19 @@ class test():
         tmp = []
         for file in self.copy_from:
             file = file.strip()
-            file = os.path.normpath(self.path + "/" + file)
-            tmp.append(file)
+            # If file is empty we do not want to add it to the list
+            if not file == "":
+                # If we get an absolut path we do nothing
+                # If not we add self.path to get an absolut path
+                if not os.path.isabs(file):
+                    file = os.path.normpath(self.path + "/" + file)
+
+                # We need to check if file is a valid file or dir
+                if not (os.path.isdir(file) or os.path.isfile(file)):
+                    raise TestException("'{}' is not a valid file nor a valid directory".format(file))
+
+                self.log.debug("'{}' will be copied into all images".format(file))
+                tmp.append(file)
 
         self.copy_from = tmp