From: Dobrica Pavlinusic Date: Fri, 22 Jun 2012 14:08:41 +0000 (+0200) Subject: bak link host:/source/path.txt X-Git-Url: http://git.rot13.org/?a=commitdiff_plain;ds=inline;h=1f42f8cda6eec5a99e660a929043934a896e5816;p=bak-git.git bak link host:/source/path.txt --- diff --git a/bak-git-server.pl b/bak-git-server.pl index 4acf227..58d4dfe 100755 --- a/bak-git-server.pl +++ b/bak-git-server.pl @@ -165,6 +165,13 @@ sub pull_changes { rsync split / /, "-avv --files-from /tmp/$hostname.list root\@$hostname:/ $hostname/"; } +sub mkbasedir { + my $path = shift; + $path =~ s{/[^/]+$}{}; + warn "# mkpath $path\n"; + mkpath $path || die $!; +} + while (my $client = $server->accept()) { my $line = <$client>; chomp($line); @@ -264,8 +271,18 @@ while (my $client = $server->accept()) { print $client `git show $rel_path`; } elsif ( $command eq 'grep' ) { print $client `git log -g --grep=$rel_path`; + } elsif ( $command eq 'link' ) { + if ( $on_host ) { + mkbasedir "$on_host/$path"; + rsync( '-avv', "root\@$on_host:$path", "$on_host/$path" ); + mkbasedir "$hostname/$path"; + link "$on_host/$path", "$hostname/$path"; + rsync( '-avv', "$hostname/$path", "root\@$hostname:$path" ); + } else { + print $client "ERROR: link requires host:/path\n"; + } } else { - print $client "Unknown command: $command\n"; + print $client "ERROR: unknown command: $command\n"; } close($client);