From: Jonatan Schlag Date: Wed, 6 Jun 2018 12:57:52 +0000 (+0200) Subject: Improve handling of file which should be copied into the image X-Git-Url: http://git.ipfire.org/?p=nitsi.git;a=commitdiff_plain;h=f010720b363975c7b5a3799cef94ba8a9aa423ff Improve handling of file which should be copied into the image 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 --- diff --git a/src/nitsi/test.py b/src/nitsi/test.py index c49c0f3..e1ae24c 100755 --- a/src/nitsi/test.py +++ b/src/nitsi/test.py @@ -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