public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stoiko Ivanov <s.ivanov@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates
Date: Fri,  7 Jul 2023 18:54:25 +0200	[thread overview]
Message-ID: <20230707165428.94777-2-s.ivanov@proxmox.com> (raw)
In-Reply-To: <20230707165428.94777-1-s.ivanov@proxmox.com>

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@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





  reply	other threads:[~2023-07-07 16:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-07 16:54 [pmg-devel] [PATCH pmg-api 0/4] add notification about unmodified template-overrides Stoiko Ivanov
2023-07-07 16:54 ` Stoiko Ivanov [this message]
2023-07-10 10:02   ` [pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates Thomas Lamprecht
2023-07-07 16:54 ` [pmg-devel] [PATCH pmg-api 2/4] pmg7to8: notify about " Stoiko Ivanov
2023-07-11 15:20   ` [pmg-devel] applied: " Thomas Lamprecht
2023-07-07 16:54 ` [pmg-devel] [PATCH pmg-api 3/4] report: skip irrelevant files in /etc/pmg/templates Stoiko Ivanov
2023-07-11 15:20   ` [pmg-devel] applied: " Thomas Lamprecht
2023-07-07 16:54 ` [pmg-devel] [PATCH pmg-api 4/4] report: group use statements Stoiko Ivanov
2023-07-11 15:19   ` [pmg-devel] applied: " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230707165428.94777-2-s.ivanov@proxmox.com \
    --to=s.ivanov@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal