From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pmg-devel@lists.proxmox.com, Stoiko Ivanov <s.ivanov@proxmox.com>
Subject: Re: [pmg-devel] [PATCH pmg-api 2/4] api: spamassassin: read local channels
Date: Wed, 30 Dec 2020 14:07:14 +0100 [thread overview]
Message-ID: <1609333126.u0qqj6cegn.astroid@nora.none> (raw)
In-Reply-To: <20201216171813.29694-3-s.ivanov@proxmox.com>
On December 16, 2020 6:18 pm, Stoiko Ivanov wrote:
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> the patch of src/PMG/API2/SpamAssassin mostly indents code and I found it
> helpful to view it with `git diff -w`
>
> src/PMG/API2/SpamAssassin.pm | 83 +++++++++++++++++++++---------------
> 1 file changed, 49 insertions(+), 34 deletions(-)
>
> diff --git a/src/PMG/API2/SpamAssassin.pm b/src/PMG/API2/SpamAssassin.pm
> index eab02d9..5f9c3a5 100644
> --- a/src/PMG/API2/SpamAssassin.pm
> +++ b/src/PMG/API2/SpamAssassin.pm
> @@ -80,50 +80,65 @@ __PACKAGE__->register_method({
> my ($param) = @_;
>
> my $saversion = $Mail::SpamAssassin::VERSION;
> - my $channelfile = "/var/lib/spamassassin/$saversion/updates_spamassassin_org.cf";
> + my $sa_update_dir = "/var/lib/spamassassin/$saversion/";
> +
> + my $check_channel = sub {
> + my ($channel) = @_;
> +
> + # taken from sa-update:
> + my $channel_file_base = $channel;
> + $channel_file_base =~ tr/A-Za-z0-9-/_/cs;
this is syntax we don't use anywhere else, so maybe add a comment or
rewrite it using a regular replacement?
> + my $channelfile = "${sa_update_dir}${channel_file_base}.cf";
> +
> + my $mtime = -1;
> + my $version = -1;
> + my $newversion = -1;
> +
> + if (-f $channelfile) {
> + # stat metadata cf file
> + $mtime = (stat($channelfile))[9]; # 9 is mtime
> +
> + # parse version from metadata cf file
> + my $metadata = PVE::Tools::file_read_firstline($channelfile);
> + if ($metadata =~ m/\s([0-9]+)$/) {
> + $version = $1;
> + } else {
> + warn "invalid metadata in '$channelfile'\n";
> + }
> + }
> + # call sa-update to see if updates are available
>
> - my $mtime = -1;
> - my $version = -1;
> - my $newversion = -1;
> + my $cmd = "$SAUPDATE -v --checkonly --channel $channel";
> + PVE::Tools::run_command($cmd, noerr => 1, logfunc => sub {
> + my ($line) = @_;
>
> - if (-f $channelfile) {
> - # stat metadata cf file
> - $mtime = (stat($channelfile))[9]; # 9 is mtime
> + if ($line =~ m/Update available for channel \S+: -?[0-9]+ -> ([0-9]+)/) {
> + $newversion = $1;
> + }
> + });
>
> - # parse version from metadata cf file
> - my $metadata = PVE::Tools::file_read_firstline($channelfile);
> - if ($metadata =~ m/\s([0-9]+)$/) {
> - $version = $1;
> - } else {
> - warn "invalid metadata in '$channelfile'\n";
> - }
> - }
> - # call sa-update to see if updates are available
> + my $result = {
> + channel => $channel,
> + };
>
> - my $cmd = "$SAUPDATE -v --checkonly";
> - PVE::Tools::run_command($cmd, noerr => 1, logfunc => sub {
> - my ($line) = @_;
> + $result->{version} = $version if $version > -1;
> + $result->{update_version} = $newversion if $newversion > -1;
> + $result->{last_updated} = $mtime if $mtime > -1;
>
> - if ($line =~ m/Update available for channel \S+: -?[0-9]+ -> ([0-9]+)/) {
> - $newversion = $1;
> + if ($newversion > $version) {
> + $result->{update_avail} = 1;
> + } else {
> + $result->{update_avail} = 0;
> }
> - });
> -
> - my $result = {
> - channel => 'updates.spamassassin.org',
> + return $result;
> };
>
> - $result->{version} = $version if $version > -1;
> - $result->{update_version} = $newversion if $newversion > -1;
> - $result->{last_updated} = $mtime if $mtime > -1;
> + my @channels = ('updates.spamassassin.org');
>
> - if ($newversion > $version) {
> - $result->{update_avail} = 1;
> - } else {
> - $result->{update_avail} = 0;
> - }
> + my $localchannels = PMG::Utils::local_spamassassin_channels();
> + push(@channels, map { $_->{channelurl} } @$localchannels);
>
> - return [$result];
> + return [ map { $check_channel->($_) } @channels];
> }});
>
> __PACKAGE__->register_method({
> --
> 2.20.1
>
>
>
> _______________________________________________
> pmg-devel mailing list
> pmg-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel
>
>
>
next prev parent reply other threads:[~2020-12-30 13:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-16 17:18 [pmg-devel] [PATCH pmg-api 0/4] add support for locally configured SA channels Stoiko Ivanov
2020-12-16 17:18 ` [pmg-devel] [PATCH pmg-api 1/4] add helper for parsing SA channel.d files Stoiko Ivanov
2020-12-30 13:07 ` Fabian Grünbichler
2020-12-16 17:18 ` [pmg-devel] [PATCH pmg-api 2/4] api: spamassassin: read local channels Stoiko Ivanov
2020-12-30 13:07 ` Fabian Grünbichler [this message]
2020-12-16 17:18 ` [pmg-devel] [PATCH pmg-api 3/4] api: spamassassin: update " Stoiko Ivanov
2020-12-30 13:07 ` Fabian Grünbichler
2020-12-30 16:11 ` Stoiko Ivanov
2020-12-16 17:18 ` [pmg-devel] [PATCH pmg-api 4/4] pmg-daily: run sa-update for " Stoiko Ivanov
2020-12-30 13:07 ` Fabian Grünbichler
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=1609333126.u0qqj6cegn.astroid@nora.none \
--to=f.gruenbichler@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