line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::bifsync; |
2
|
1
|
|
|
1
|
|
22707
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
432
|
use App::bif; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
1494
|
use AnyEvent; |
|
1
|
|
|
|
|
5922
|
|
|
1
|
|
|
|
|
33
|
|
6
|
1
|
|
|
1
|
|
504
|
use Bif::DBW; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
109
|
|
7
|
1
|
|
|
1
|
|
41
|
use Bif::Mo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
604
|
use Bif::Sync::Server; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Coro; |
10
|
|
|
|
|
|
|
use Log::Any '$log'; |
11
|
|
|
|
|
|
|
use Log::Any::Adapter; |
12
|
|
|
|
|
|
|
use Log::Any::Plugin; |
13
|
|
|
|
|
|
|
use OptArgs; |
14
|
|
|
|
|
|
|
use Path::Tiny; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.1.5_6'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub DBVERSION { 1 } |
19
|
|
|
|
|
|
|
sub DBFILE { 'db-v' . DBVERSION . '.sqlite3' } |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
arg directory => ( |
22
|
|
|
|
|
|
|
isa => 'Str', |
23
|
|
|
|
|
|
|
comment => 'location of bif repository', |
24
|
|
|
|
|
|
|
default => 'defauln.bif', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
opt debug => ( |
28
|
|
|
|
|
|
|
isa => 'Bool', |
29
|
|
|
|
|
|
|
comment => 'add debugging statements to stderr', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# class |
33
|
|
|
|
|
|
|
has opts => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
required => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub run { |
39
|
|
|
|
|
|
|
my $self = shift; |
40
|
|
|
|
|
|
|
my $opts = $self->opts; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# no buffering |
43
|
|
|
|
|
|
|
$|++; |
44
|
|
|
|
|
|
|
my $tmp = select STDERR; |
45
|
|
|
|
|
|
|
$|++; |
46
|
|
|
|
|
|
|
select $tmp; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $dir = path( $opts->{directory} ); |
49
|
|
|
|
|
|
|
my $sqlite = $dir->child(DBFILE); |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
die Bif::Error->new( $opts, 'RepoNotFound', "directory not found: $dir\n" ) |
52
|
|
|
|
|
|
|
unless -e $dir; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
if ( !-f $sqlite ) { |
55
|
|
|
|
|
|
|
$log->error( 'file not found: ' . $sqlite ); |
56
|
|
|
|
|
|
|
die Bif::Error->new( $opts, 'FileNotFound', |
57
|
|
|
|
|
|
|
"file not found: $sqlite\n" ); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
if ( $opts->{debug} ) { |
60
|
|
|
|
|
|
|
Log::Any::Adapter->set('Stderr'); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
else { |
63
|
|
|
|
|
|
|
# TODO use Syslog (when development is stable) |
64
|
|
|
|
|
|
|
Log::Any::Adapter->set('Stderr'); |
65
|
|
|
|
|
|
|
Log::Any::Plugin->add( 'Levels', level => 'warning' ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$log->debug( 'db: ' . $sqlite ); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
my $err; |
71
|
|
|
|
|
|
|
my $cv = AnyEvent->condvar; |
72
|
|
|
|
|
|
|
my $db = Bif::DBW->connect( 'dbi:SQLite:dbname=' . $sqlite, |
73
|
|
|
|
|
|
|
undef, undef, undef, $opts->{debug} ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
my $server = Bif::Sync::Server->new( |
76
|
|
|
|
|
|
|
db => $db, |
77
|
|
|
|
|
|
|
debug => $opts->{debug}, |
78
|
|
|
|
|
|
|
on_error => sub { |
79
|
|
|
|
|
|
|
$err = shift; |
80
|
|
|
|
|
|
|
}, |
81
|
|
|
|
|
|
|
); |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $coro = async { |
84
|
|
|
|
|
|
|
$server->run; |
85
|
|
|
|
|
|
|
$server->disconnect; |
86
|
|
|
|
|
|
|
$cv->send; |
87
|
|
|
|
|
|
|
}; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $sig = AE::signal 'INT', sub { |
90
|
|
|
|
|
|
|
$coro->cancel; |
91
|
|
|
|
|
|
|
$server->disconnect('INT'); |
92
|
|
|
|
|
|
|
$cv->send; |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$cv->recv; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
return Bif::Error->new( $opts, 'Bifsync', $err ) if $err; |
98
|
|
|
|
|
|
|
return Bif::OK->new( $opts, 'BifSync' ); |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
__END__ |