MYDan
view release on metacpan or search on metacpan
dan/agent/code/edump view on Meta::CPAN
#!/usr/bin/env perl
use strict;
use warnings;
use YAML::XS;
use File::Temp;
use MYDan::Util::FastMD5;
local $/ = undef;
my %param = %{ YAML::XS::Load( <> ) };
my $conf = $param{argv};
my $path = delete $conf->{path};
my ( $fh, $temp ) = File::Temp::tempfile();
my $idie = sub{ print shift;exit 1; };
my $unlink = sub { unlink shift; print shift; exit 1 };
&$idie( 'param error' ) unless defined $conf->{md5}
&& $path && $fh && length $param{data};
&$idie( "get $conf->{chown} uid fail" ) if $conf->{chown} && ! ( my @pw = getpwnam $conf->{chown} );
print $fh $param{data};
close $fh;
my $md5 = MYDan::Util::FastMD5->hexdigest( $temp );
&$unlink( $temp, 'chomd fail' ) if $conf->{chmod}
&& ! chmod oct $conf->{chmod}, $temp;
&$unlink( $temp, 'chown fail' ) if @pw && ! chown @pw[2,3], $temp;
&$unlink( $temp, 'md5 nomatch' ) if $md5 ne $conf->{md5};
&$unlink( $temp, 'rename fail' ) if system "mv '$temp' '$path'";
print "ok\n";
exit 0;
( run in 0.571 second using v1.01-cache-2.11-cpan-71847e10f99 )