rename_file Gearman API
[cloudstore.git] / gearman / send_file.pl
index 944df9a..752f7b1 100755 (executable)
@@ -44,6 +44,27 @@ $worker->register_function( send_file => sub {
        return "send_file $f_dir $from -> $t_dir $to";
 });
 
+$worker->register_function( rename_file => sub {
+       my ($job) = @_;
+
+       my $work = $job->arg;
+       chomp $work;
+       warn "# rename_file [$work]\n";
+
+       my ( $from, $to ) = split(/#/,$work,2);
+
+       my $dir = home_dir($1) if $from =~ s/~(\w+)//;
+
+       warn "rename_file $dir $from -> $to\n";
+
+       rename $dir . $from => $dir . $to;
+
+       print "rename#$work#", -s $dir.$to, "#$!\n";
+
+       die "ERROR: $!" if $!;
+
+       return "rename_file $dir $from -> $to";
+});
 
 $worker->register_function( delete => sub {
        my ($job) = @_;