rename_file Gearman API
authorDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Wed, 7 Dec 2011 22:11:06 +0000 (23:11 +0100)
committerDobrica Pavlinusic <dpavlin@rsync1.maxxo.com>
Wed, 7 Dec 2011 22:11:06 +0000 (23:11 +0100)
gearman/send_file.pl
test-gearman.sh

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) = @_;
index 01eee6e..8694d1f 100755 (executable)
@@ -8,6 +8,11 @@ echo '~u2001/foo.txt#~u2002/dir with space/file with space' | gearman -f send_fi
 
 echo '~u2002/dir with space/file with space' | gearman -f delete -n
 
+echo '~u2002/foo.txt#bar.txt' | gearman -f rename_file -n
+echo '~u2002/bar.txt#baz.txt' | gearman -f rename_file -n
+
+echo '~u2002/baz.txt' | gearman -f delete -n
+
 echo u2001 | gearman -f zfs_userquota -n
 echo u2001 | gearman -f zfs_userused -n
 echo u2001 | gearman -f zfs_userspace -n