[pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates

Stoiko Ivanov s.ivanov at proxmox.com
Fri Jul 7 18:54:25 CEST 2023


find_unmodified_templates yields a list of overridden templates in
/etc/pmg/templates, which have no change to the one they replace from
/var/lib/pmg/templates.

In practice this should only be a cosmetic problem, since the ones
in /etc/pmg/templates would get updated to the new version in
/var/lib/pmg/templates, by ucf if they have no changes.
(There would be a dialog asking what to do if there was a change, as
with sshd_config). However it can cause confusion also when providing
support, and experience shows that there are quite a few installs,
which have all templates copied (only to make a small modification to
one).

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PMG/Utils.pm | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 6405934..f0d31c1 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -1573,4 +1573,24 @@ sub try_decode_utf8 {
     return eval { decode('UTF-8', $data, 1) } // $data;
 }
 
+sub find_unmodified_templates {
+    my $res = [];
+
+    my $template_dir = '/var/lib/pmg/templates';
+    my $override_dir = '/etc/pmg/templates';
+
+    PVE::Tools::dir_glob_foreach('/var/lib/pmg/templates', '.*\.(?:tt|in).*', sub {
+	my ($filename) = @_;
+	if ( -e "$override_dir/$filename") {
+	    my $shipped = PVE::Tools::file_get_contents("$template_dir/$filename", 1024*1024);
+	    my $override = PVE::Tools::file_get_contents("$override_dir/$filename", 1024*1024);
+	    if ( $shipped eq $override ) {
+		push (@$res, $filename);
+	    }
+	}
+    });
+
+    return $res;
+}
+
 1;
-- 
2.39.2





More information about the pmg-devel mailing list