[pmg-devel] [PATCH pmg-api 1/4] utils: add helper for unmodified templates
Thomas Lamprecht
t.lamprecht at proxmox.com
Mon Jul 10 12:02:55 CEST 2023
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 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") {
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;
More information about the pmg-devel
mailing list