#!# perl: agent/argv/xdump
use strict;
use warnings;

use Cwd;
use Getopt::Long;
use MYDan::Util::FastMD5;

return sub
{
    local $/;
    my ( $file, %o ) = shift;
    return [ %o ] unless $file && -f $file;

    %o = ( path => $file =~ /^\// ? $file : Cwd::abs_path( $file ) );

    Getopt::Long::GetOptionsFromArray( \@_, \%o, qw( path=s chmod=s chown=s cc ) );

    if( delete $o{cc} )
    {
        my ( $uid, $mode ) = ( stat $file )[ 4, 2 ];
        $o{chmod} ||= $mode = sprintf( "%04o", $mode & 07777 );
	$o{chown} ||= ( getpwuid($uid) )[0];
    }

    $o{md5} = MYDan::Util::FastMD5->hexdigest( $file );

    $ENV{MYDanExtractFile} = $file;
    $ENV{MYDanExtractFileAim} = $o{path};

    return \%o;
};
