| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package CogBase::Connection::FileSystem; |
|
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use CogBase::Connection -base; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
11
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use IO::All; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub fetch_node { |
|
8
|
0
|
|
|
0
|
0
|
0
|
my ($self, $node) = @_; |
|
9
|
0
|
|
|
|
|
0
|
my $node_path = $self->_node_path($node); |
|
10
|
0
|
|
|
|
|
0
|
for my $file ($node_path->all_files) { |
|
11
|
0
|
|
|
|
|
0
|
my ($field, $value) = ($file->filename, $file->all); |
|
12
|
0
|
0
|
|
|
|
0
|
if ($field eq '!') { |
|
13
|
0
|
|
|
|
|
0
|
bless $node, "CogBase::$value"; |
|
14
|
|
|
|
|
|
|
} |
|
15
|
|
|
|
|
|
|
else { |
|
16
|
0
|
|
|
|
|
0
|
$node->{$field} = $value; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub store_node { |
|
22
|
1
|
|
|
1
|
0
|
3
|
my ($self, $node) = @_; |
|
23
|
1
|
50
|
|
|
|
31
|
$self->_set_new_id($node) unless ($node->Id); |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
|
|
12
|
my $node_path = $self->_node_path($node); |
|
26
|
1
|
|
|
|
|
777
|
my $head_path = $self->_head_path($node); |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
324
|
for my $field ($node->_fields) { |
|
29
|
1
|
|
|
|
|
6
|
io->catfile($node_path, $field)->assert->print($node->$field); |
|
30
|
|
|
|
|
|
|
} |
|
31
|
1
|
|
|
|
|
1589
|
io->catfile($node_path, '!')->assert->print($node->Type); |
|
32
|
1
|
|
|
|
|
718
|
symlink($node->Revision, $head_path); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub query { |
|
36
|
1
|
|
|
1
|
0
|
2
|
my ($self, $query) = @_; |
|
37
|
1
|
50
|
|
|
|
30
|
die "Invalid query '$query'" |
|
38
|
|
|
|
|
|
|
unless $query =~ /^!(\w+)$/; |
|
39
|
1
|
|
|
|
|
4
|
my $query_type = $1; |
|
40
|
1
|
|
|
|
|
6
|
my $nodes_path = io->catdir( $self->db_location, 'nodes' ); |
|
41
|
1
|
|
|
|
|
342
|
my $results = []; |
|
42
|
1
|
|
|
|
|
20
|
while (my $dir = $nodes_path->readdir) { |
|
43
|
1
|
|
|
|
|
227
|
my $type_file = io->catfile($nodes_path, $dir, '0'); |
|
44
|
1
|
50
|
|
|
|
229
|
next unless $type_file->exists; |
|
45
|
0
|
|
|
|
|
0
|
my $head_revision = $type_file->link->readlink; |
|
46
|
0
|
0
|
|
|
|
0
|
if (io->catfile($type_file, '!')->all eq $query_type) { |
|
47
|
0
|
|
|
|
|
0
|
push @$results, "$dir-$head_revision"; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
1
|
|
|
|
|
267
|
return @$results; |
|
51
|
|
|
|
|
|
|
} |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _node_path { |
|
54
|
1
|
|
|
1
|
|
4
|
my ($self, $node) = @_; |
|
55
|
1
|
50
|
33
|
|
|
23
|
ZZZ "Can't access node without Id and Revision" |
|
56
|
|
|
|
|
|
|
unless $node->Id && $node->Revision; |
|
57
|
1
|
|
|
|
|
44
|
return io->catdir( |
|
58
|
|
|
|
|
|
|
$self->db_location, |
|
59
|
|
|
|
|
|
|
'nodes', |
|
60
|
|
|
|
|
|
|
$node->Id, |
|
61
|
|
|
|
|
|
|
$node->Revision |
|
62
|
|
|
|
|
|
|
); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub _head_path { |
|
66
|
1
|
|
|
1
|
|
23
|
my ($self, $node) = @_; |
|
67
|
1
|
|
|
|
|
6
|
return io->catdir( |
|
68
|
|
|
|
|
|
|
$self->db_location, |
|
69
|
|
|
|
|
|
|
'nodes', |
|
70
|
|
|
|
|
|
|
$node->Id, |
|
71
|
|
|
|
|
|
|
'0' |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _set_new_id { |
|
76
|
1
|
|
|
1
|
|
20
|
my ($self, $node) = @_; |
|
77
|
1
|
|
|
|
|
3
|
my $id; |
|
78
|
1
|
|
|
|
|
8
|
while ($id = _generate_id()) { |
|
79
|
1
|
50
|
|
|
|
7
|
$id = $self->_unique_id($id) |
|
80
|
|
|
|
|
|
|
or next; |
|
81
|
1
|
|
|
|
|
3
|
last; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
1
|
|
|
|
|
58
|
$node->Id($id); |
|
84
|
1
|
|
|
|
|
39
|
$node->Revision(1); |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub _unique_id { |
|
88
|
1
|
|
|
1
|
|
3
|
my ($self, $id) = @_; |
|
89
|
1
|
|
|
|
|
10
|
$id =~ s/(...)/$1-/; |
|
90
|
1
|
|
|
|
|
7
|
return $id; |
|
91
|
|
|
|
|
|
|
} |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub _generate_id { |
|
94
|
1
|
50
|
|
1
|
|
7
|
if (defined $CogBase::TEST_COGBASE_IDS) { |
|
95
|
1
|
|
|
|
|
72
|
my $id = <$CogBase::TEST_COGBASE_IDS>; |
|
96
|
1
|
|
|
|
|
3
|
chomp $id; |
|
97
|
1
|
|
|
|
|
9
|
return $id; |
|
98
|
|
|
|
|
|
|
} |
|
99
|
|
|
|
|
|
|
return uc( |
|
100
|
0
|
|
|
|
|
|
Convert::Base32::encode_base32( |
|
101
|
|
|
|
|
|
|
Digest::MD5::md5( |
|
102
|
|
|
|
|
|
|
Data::UUID->new->create_str() |
|
103
|
|
|
|
|
|
|
) |
|
104
|
|
|
|
|
|
|
) |
|
105
|
|
|
|
|
|
|
); |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
1; |