SI/tools.pm
changeset 12 a1aee1136609
parent 11 42c603eb6301
child 13 2e3ad71484ea
--- a/SI/tools.pm	Sun Jan 17 16:40:08 2010 +0100
+++ b/SI/tools.pm	Mon Jan 18 20:35:27 2010 +0100
@@ -4,8 +4,10 @@
 
 use strict;
 use warnings;
+use File::Find;
 use base "Exporter";
-our @EXPORT = qw(&run &verbose);
+
+our @EXPORT = qw(&run &verbose &find_by_devid);
 
 sub run(@) {
 	system(@_);
@@ -21,5 +23,21 @@
     $last = substr($_[-1], -1, 1);
 };
 
+sub find_by_devid($$) {
+    my ($dir, $id) = @_;
+    my @found;
+    find(
+        sub {
+            push @found, $File::Find::name if (stat)[6] == $id;
+            return;
+        },
+        $dir
+    );
+    die "ERR: found more than one alias (@found) for $id\n" if @found > 1;
+    die "ERR: found no alias for $id\n" if not @found;
+    return $found[0];
+}
+
+
 1;
 # vim:sts=4 sw=4 aw ai si: