API workers using Gearman::Driver
[cloudstore.git] / gearman / transmission.pl
index 1d7d729..6e6e04a 100755 (executable)
@@ -24,7 +24,8 @@ my $j = JSON::XS->new;
 $j->allow_blessed(1);
 $j->convert_blessed(0);
 
-use TokyoCabinet;
+use lib 'lib';
+use CloudStore::MD5sum;
 
 my $name = $ENV{ZSLICE} || die "need ZSLICE";
 my $torrent_dir = "/$name/torrent";
@@ -87,9 +88,6 @@ $worker->register_function( $name . '_torrent_download_done' => sub {
 
        my ( $id, $dir, $name, $hash ) = split(/\s+#\s+/,$work);
 
-       my $t = $tc->remove( $id );
-       warn "# remove $id = ",dump($t);
-
        if ( $dir =~ m{/download/(\w+)/(.+)$} ) {
                my $user = $1;
                my $path = $2;
@@ -107,13 +105,16 @@ $worker->register_function( $name . '_torrent_download_done' => sub {
                chown $uid, $gid,  "$home_dir/$path";
                warn "FIXME: add to md5 pool?";
 
+               my $t = $tc->remove( $id );
+               warn "# remove $id = ",dump($t);
+
+               warn "# $id removed $dir $name $hash\n";
+
+               remove_tree $dir;
        } else {
                warn "ERROR: can't find user in $dir for $name\n";
        }
 
-       warn "# $id removed $dir $name $hash\n";
-
-       remove_tree $dir;
 
 } );
 
@@ -132,11 +133,7 @@ $worker->register_function( $name . '_torrent_share' => sub {
        my $path = $work;
 
        my $dir = (getpwnam($user))[7] || die "no user $user";
-       my $md5_path = "$dir/.md5";
-       my %h;
-       tie %h, "TokyoCabinet::HDB", $md5_path || die "$md5_path: $!";
-       my $md5 = $h{$path} || die "can't find $path in $md5_path";
-       untie %h;
+       my $md5 = CloudStore::MD5sum->md5_get( "$dir/$path" );
 
        warn "# $md5 $path";