<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package GLPI::Agent::Task::Deploy::CheckProcessor::FileSHA512Mismatch;

use strict;
use warnings;

use Digest::SHA;

use English qw(-no_match_vars);

use parent "GLPI::Agent::Task::Deploy::CheckProcessor";

# This processor could be used to skip file deployment as expected file is found
# So we should only trigger a failure is we can compute sha512 and it is wrong

sub prepare {
}

sub success {
    my ($self) = @_;

    my $path = $self-&gt;{path};

    $self-&gt;on_success("$path file is missing");
    return 1 unless -f $path;

    $self-&gt;on_success("no value provided to check file size against");
    my $expected = $self-&gt;{value};
    return 1 unless (defined($expected));

    $self-&gt;on_success("sha512 hash computing not supported by agent");
    my $sha = Digest::SHA-&gt;new('512');
    return 1 unless (defined($sha));

    my $sha512 = "";
    eval {
        $sha-&gt;addfile($path, 'b');
        $sha512 = $sha-&gt;hexdigest;
    };
    $self-&gt;on_success("$path file sha512 hash computing failed, $EVAL_ERROR");
    return 1 unless (defined($sha512) &amp;&amp; $sha512);

    $self-&gt;on_failure("got sha512 file hash match for $path");
    $self-&gt;on_success("got sha512 file hash mismatch for $path, found $sha512");
    return ( $sha512 ne $expected );
}

1;
</pre></body></html>