From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Stoiko Ivanov <s.ivanov@proxmox.com>, pmg-devel@lists.proxmox.com
Subject: Re: [pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates
Date: Mon, 10 Jul 2023 12:02:55 +0200 [thread overview]
Message-ID: <a4212c3f-bacf-aaec-e47b-c7c7e5aa529b@proxmox.com> (raw)
In-Reply-To: <20230707165428.94777-2-s.ivanov@proxmox.com>
Am 07/07/2023 um 18:54 schrieb Stoiko Ivanov:
> 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.
>
are we planning in reusing this for other things? as otherwise it might be
better to have it in pmg7to8 directly.
> 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") {
style issue: extra leading whitespace in if-test expression.
also, we often use an early "return" like `next if !-e "...";` to avoid an indentation for the
rest of the block for such must-have conditions for the whole block.
> + 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 ) {
style issue: extra leading and trailing whitespace in if-test expression
> + push (@$res, $filename);
> + }
> + }
> + });
> +
> + return $res;
> +}
> +
> 1;
next prev parent reply other threads:[~2023-07-10 10:03 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 ` [pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates Stoiko Ivanov
2023-07-10 10:02 ` Thomas Lamprecht [this message]
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=a4212c3f-bacf-aaec-e47b-c7c7e5aa529b@proxmox.com \
--to=t.lamprecht@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
--cc=s.ivanov@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