App-MBUtiny

 view release on metacpan or  search on metacpan

lib/App/MBUtiny/Storage/Command.pm  view on Meta::CPAN

    my $name = $params{name}; # File name only
    my $file = $params{file}; # Path to local file
    my $src_size = $params{size} || 0;

    foreach my $storage ($self->cmd_storages) {
        my $attr = $storage->{attr};
           $attr->{SIZE} = $src_size;
           $attr->{NAME} = $name;
           $attr->{FILE} = $file;
        my $cmd_put = dformat($storage->{cmd_put}, $attr);
        my $comment = $storage->{comment} || "";
        my $ostat = 1;

        # Execute
        my $exe_err = '';
        my $exe_out = execute($cmd_put, undef, \$exe_err);
        my $exe_stt = $? >> 8;
        if ($exe_stt) {
            $self->error(sprintf("Can't execute %s", $cmd_put));
            $self->error($exe_out) if $exe_out;
            $self->error($exe_err) if $exe_err;
            $ostat = 0;
        }
        #print explain($exe_out), "\n";

        # Fixup!
        $self->fixup("put", $ostat, $comment) if $storage->{fixup};
        $status = 0 unless $ostat;
    }

    $self->storage_status(STORAGE_SIGN, 0) unless $status;
}
sub get {
    my $self = shift;
    my %params = @_;
    if ($self->storage_status(STORAGE_SIGN) <= 0) { # SKIP and set SKIP
        $self->maybe::next::method(%params);
        return $self->storage_status(STORAGE_SIGN, -1);
    }
    my $name = $params{name}; # archive name
    my $file = $params{file}; # destination archive file path

    foreach my $storage ($self->cmd_storages) {
        my $attr = $storage->{attr};
           $attr->{NAME} = $name;
           $attr->{FILE} = $file;
        my $cmd_get = dformat($storage->{cmd_get}, $attr);

        # Execute
        my $exe_err = '';
        my $exe_out = execute($cmd_get, undef, \$exe_err);
        my $exe_stt = $? >> 8;
        if ($exe_stt) {
            $self->error(sprintf("Can't execute %s", $cmd_get));
            $self->error($exe_out) if $exe_out;
            $self->error($exe_err) if $exe_err;
            next;
        }

        # Validate
        unless ($self->validate($file)) { # FAIL validation!
            $self->error(sprintf("Command storage %s failed: file %s is not valid!", $cmd_get, $file));
            next
        }

        # Done!
        return $self->storage_status(STORAGE_SIGN, 1);
    }

    $self->storage_status(STORAGE_SIGN, 0);
    $self->maybe::next::method(%params);
}
sub del {
    my $self = shift;
    my $name = shift;
    $self->maybe::next::method($name);
    return $self->storage_status(STORAGE_SIGN, -1) if $self->storage_status(STORAGE_SIGN) <= 0; # SKIP and set SKIP
    my $status = 1;

    foreach my $storage ($self->cmd_storages) {
        my $attr = $storage->{attr};
           $attr->{NAME} = $name;
        my $cmd_del = dformat($storage->{cmd_del}, $attr);
        my $comment = $storage->{comment} || "";
        my $ostat = 1;

        # Execute
        my $exe_err = '';
        my $exe_out = execute($cmd_del, undef, \$exe_err);
        my $exe_stt = $? >> 8;
        if ($exe_stt) {
            $self->error(sprintf("Can't execute %s", $cmd_del));
            $self->error($exe_out) if $exe_out;
            $self->error($exe_err) if $exe_err;
            $ostat = 0;
        }

        # Fixup!
        $self->fixup("del", $name) if $storage->{fixup};
        $status = 0 unless $ostat;
    }
    $self->storage_status(STORAGE_SIGN, 0) unless $status;
}
sub list {
    my $self = shift;
    my %params = @_; $self->maybe::next::method(%params);
    return $self->storage_status(STORAGE_SIGN, -1) if $self->storage_status(STORAGE_SIGN) <= 0; # SKIP and set SKIP
    my $sign = STORAGE_SIGN;

    my @list = ();
    foreach my $storage ($self->cmd_storages) {
        my $attr = $storage->{attr};
        my $cmd_list = dformat($storage->{cmd_list}, $attr);
        my $ostat = 1;

        # Execute
        my $exe_err = '';
        my $exe_out = execute($cmd_list, undef, \$exe_err);
        my $exe_stt = $? >> 8;
        if ($exe_stt) {
            $self->error(sprintf("Can't execute %s", $cmd_list));



( run in 0.536 second using v1.01-cache-2.11-cpan-39bf76dae61 )