]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/replica/pull
use /n/other for tmp storage
[plan9front.git] / rc / bin / replica / pull
1 #!/bin/rc
2
3 rfork en
4
5 fn usage {
6         echo 'usage: replica/pull [-nv] [-c name] [-s name] replica-name [paths]' >[1=2]
7         exit usage
8 }
9
10 . /rc/bin/replica/defs $*
11
12 need clientlog serverlog clientdb clientroot serverroot
13
14 # mount the server file system, update the log
15 must servermount
16 must serverupdate
17 must clientmount
18
19 # download the log
20 n=`{ls -l $clientlog >[2]/dev/null |awk '{print $6}'}
21 s=`{ls -l $serverlog >[2]/dev/null |awk '{print $6}'}
22 if(~ $n 0 || ~ $#n 0 || test $s -lt $n){
23         if(test -e $clientlog) must rm $clientlog
24         must fcp $serverlog $clientlog
25 }
26 if not{
27         m=`{echo $n-1024 | hoc}
28         if(~ $m -*)
29                 m=0
30         cmp -s $serverlog $clientlog $m $m
31         x=$status
32         switch($x){
33         case *': EOF'
34                 must tail +^$n^c $serverlog >>$clientlog
35         case *': differ'
36                 must rm $clientlog
37                 must fcp $serverlog $clientlog
38         case ''
39                 ;
40         case *
41                 fatal cmp: $x
42         }
43 }
44
45 # normally we'd do this after applylog, but we want
46 # applylog to be the last thing in this script, so we'll
47 # do it here instead, compacting changes from the
48 # _last_ applylog.
49
50 ndb=`{echo $clientdb | sed 's;(.*)/(.*);\1/_\2;'}
51 must replica/compactdb $clientdb >$ndb
52 mv $ndb $clientdb
53
54 # mount the client file system, apply the log
55 # this is the last thing in the script and is execed so that
56 # if replica/pull is overwritten nothing bad will happen.
57 # applylog takes care of itself as far as protection against being overwritten.
58 exec replica/applylog $opt $applyopt $clientdb $clientroot $serverroot $paths <$clientlog