summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2021-08-22 20:26:36 +0200
committerChristian Poessinger <christian@poessinger.com>2021-08-23 09:03:19 +0200
commitbedc5021091c247356840e3bcd8efc4ee60955ac (patch)
tree54ca7c43b2ed2f3d4750f1aaebabcfa84736da69
parentef4deb58b86b30630ada347c110b35dd741a9101 (diff)
downloadvyos-1x-bedc5021091c247356840e3bcd8efc4ee60955ac.tar.gz
vyos-1x-bedc5021091c247356840e3bcd8efc4ee60955ac.zip
T3165: op-mode: prevent override of populated node.def file with empty content
This is an extension to commit b4fdcebe ("T3165: prevent override of populated node.def file with empty content") which implemented the same thing for the configuration mode commands. (cherry picked from commit 17b5ac143c9128ac3e187d8d8167dd8fe6cbca7d)
-rwxr-xr-xscripts/build-command-op-templates24
1 files changed, 13 insertions, 11 deletions
diff --git a/scripts/build-command-op-templates b/scripts/build-command-op-templates
index d0e5833cc..a4d6d1d08 100755
--- a/scripts/build-command-op-templates
+++ b/scripts/build-command-op-templates
@@ -165,11 +165,11 @@ def process_node(n, tmpl_dir):
props = get_properties(props_elem)
+ nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def")
if node_type == "node":
if debug:
print(f"Processing node {name}")
- nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def")
# Only create the "node.def" file if it exists but is empty, or if it
# does not exist at all.
if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0:
@@ -187,13 +187,11 @@ def process_node(n, tmpl_dir):
os.makedirs(make_path(my_tmpl_dir), exist_ok=True)
- nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def")
- if not os.path.exists(nodedef_path):
+ # Only create the "node.def" file if it exists but is empty, or if it
+ # does not exist at all.
+ if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0:
with open(nodedef_path, "w") as f:
f.write('help: {0}\n'.format(props['help']))
- else:
- # Something has already generated this file
- pass
# Create the inner node.tag part
my_tmpl_dir.append("node.tag")
@@ -202,8 +200,12 @@ def process_node(n, tmpl_dir):
print("Created path for the tagNode: {}".format(make_path(my_tmpl_dir)), end="")
# Not sure if we want partially defined tag nodes, write the file unconditionally
- with open(os.path.join(make_path(my_tmpl_dir), "node.def"), "w") as f:
- f.write(make_node_def(props, command))
+ nodedef_path = os.path.join(make_path(my_tmpl_dir), "node.def")
+ # Only create the "node.def" file if it exists but is empty, or if it
+ # does not exist at all.
+ if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0:
+ with open(nodedef_path, "w") as f:
+ f.write(make_node_def(props, command))
if children is not None:
inner_nodes = children.iterfind("*")
@@ -214,9 +216,9 @@ def process_node(n, tmpl_dir):
if debug:
print(f"Processing leaf node {name}")
- with open(os.path.join(make_path(my_tmpl_dir), "node.def"), "w") as f:
- f.write(make_node_def(props, command))
-
+ if not os.path.exists(nodedef_path) or os.path.getsize(nodedef_path) == 0:
+ with open(nodedef_path, "w") as f:
+ f.write(make_node_def(props, command))
root = xml.getroot()