From e76bc6ead81d0ce441a02d3f047c6808362ff2ac Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Tue, 21 Nov 2023 16:45:43 +0100 Subject: [PATCH] configd / configuration templates - add helpers.file_exists to check for file existence. closes https://github.com/opnsense/core/issues/7023 --- .../service/modules/addons/template_helpers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/opnsense/service/modules/addons/template_helpers.py b/src/opnsense/service/modules/addons/template_helpers.py index f4e811b15..81c01fb7c 100644 --- a/src/opnsense/service/modules/addons/template_helpers.py +++ b/src/opnsense/service/modules/addons/template_helpers.py @@ -175,6 +175,18 @@ class Helpers(object): return [lst] return lst + @staticmethod + def file_exists(pathname): + """ + :param pathname: absolute or relative path name depending if it starts with a / + :return: bool + """ + if pathname.startswith('/'): + return os.path.isfile(pathname) + else: + template_path = os.path.realpath("%s/../../templates/" % os.path.dirname(__file__)) + return os.path.isfile("%s/%s" % (template_path, pathname)) + @staticmethod def glob(pathname): """