#!/usr/bin/env perl
use strict;
use warnings;

use MYDan::Util::OptConf;
use MYDan::Util::DiskSpaceControl;

=head1 SYNOPSIS

 $0 [--mountedOnPath /data] [--percent 90 ]

 $0 [--mountedOnPath /data] [--percent 10.1] [--interval 60]

=cut

my $option = MYDan::Util::OptConf->load();
my %o = $option->get( qw( mountedOnPath=s percent=s interval=i ) )->dump();

$option->assert( qw( mountedOnPath ) );
$option->assert() unless $o{percent} =~ /^\d+$/ || $o{percent} =~ /^\d+\.\d+$/;

my $mountedOnPath = MYDan::Util::DiskSpaceControl->new( %o );

while( 1 )
{
    my $time = time;

    $mountedOnPath->run();

    last unless $o{interval};

    my $due = $time + $o{interval} - time;
    sleep $due if $due > 0;
}
