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-22 20:26:36 +0200
commit17b5ac143c9128ac3e187d8d8167dd8fe6cbca7d (patch)
tree42782f1a3dfa6d82db2c11a154340720d1e0d710
parent252bc820b0d130d8d81b5711586eca41287abdca (diff)
downloadvyos-1x-17b5ac143c9128ac3e187d8d8167dd8fe6cbca7d.tar.gz
vyos-1x-17b5ac143c9128ac3e187d8d8167dd8fe6cbca7d.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.
-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()