SI/tools.pm
changeset 12 a1aee1136609
parent 11 42c603eb6301
child 13 2e3ad71484ea
equal deleted inserted replaced
11:42c603eb6301 12:a1aee1136609
     2 
     2 
     3 use if $ENV{DEBUG} ~~ /tools|all/ => "Smart::Comments";
     3 use if $ENV{DEBUG} ~~ /tools|all/ => "Smart::Comments";
     4 
     4 
     5 use strict;
     5 use strict;
     6 use warnings;
     6 use warnings;
       
     7 use File::Find;
     7 use base "Exporter";
     8 use base "Exporter";
     8 our @EXPORT = qw(&run &verbose);
     9 
       
    10 our @EXPORT = qw(&run &verbose &find_by_devid);
     9 
    11 
    10 sub run(@) {
    12 sub run(@) {
    11 	system(@_);
    13 	system(@_);
    12 	die "$_[0] failed with exit code " . ($? >> 8) . "\n"
    14 	die "$_[0] failed with exit code " . ($? >> 8) . "\n"
    13 	if $?;
    15 	if $?;
    19 	if not(@_ == 1 and length($_[0]) == 1);
    21 	if not(@_ == 1 and length($_[0]) == 1);
    20     print @_;
    22     print @_;
    21     $last = substr($_[-1], -1, 1);
    23     $last = substr($_[-1], -1, 1);
    22 };
    24 };
    23 
    25 
       
    26 sub find_by_devid($$) {
       
    27     my ($dir, $id) = @_;
       
    28     my @found;
       
    29     find(
       
    30         sub {
       
    31             push @found, $File::Find::name if (stat)[6] == $id;
       
    32             return;
       
    33         },
       
    34         $dir
       
    35     );
       
    36     die "ERR: found more than one alias (@found) for $id\n" if @found > 1;
       
    37     die "ERR: found no alias for $id\n" if not @found;
       
    38     return $found[0];
       
    39 }
       
    40 
       
    41 
    24 1;
    42 1;
    25 # vim:sts=4 sw=4 aw ai si:
    43 # vim:sts=4 sw=4 aw ai si: