9 |
use POSIX qw(ENOENT EISDIR EINVAL ENOSYS O_RDWR); |
use POSIX qw(ENOENT EISDIR EINVAL ENOSYS O_RDWR); |
10 |
use Fuse; |
use Fuse; |
11 |
use DBI; |
use DBI; |
12 |
|
use Carp; |
13 |
|
use Proc::Simple; |
14 |
|
use Data::Dumper; |
15 |
|
|
16 |
|
|
17 |
our $VERSION = '0.01'; |
our $VERSION = '0.01'; |
18 |
|
|
23 |
=head1 SYNOPSIS |
=head1 SYNOPSIS |
24 |
|
|
25 |
use Fuse::DBI; |
use Fuse::DBI; |
26 |
Fuse::DBI->run( ... ); |
Fuse::DBI->mount( ... ); |
27 |
|
|
28 |
See L<run> below for examples how to set parametars. |
See L<run> below for examples how to set parametars. |
29 |
|
|
43 |
|
|
44 |
=cut |
=cut |
45 |
|
|
46 |
=head2 run |
=head2 mount |
47 |
|
|
48 |
Mount your database as filesystem. |
Mount your database as filesystem. |
49 |
|
|
50 |
Fuse::DBI->run({ |
my $mnt = Fuse::DBI->mount({ |
51 |
filenames => 'select name from filenamefilenames, |
filenames => 'select name from filenamefilenames, |
52 |
read => 'sql read', |
read => 'sql read', |
53 |
update => 'sql update', |
update => 'sql update', |
62 |
my $sth; |
my $sth; |
63 |
my $ctime_start; |
my $ctime_start; |
64 |
|
|
65 |
sub run { |
sub read_filenames; |
66 |
my $self = shift |
|
67 |
|
sub mount { |
68 |
|
my $class = shift; |
69 |
|
my $self = {}; |
70 |
|
bless($self, $class); |
71 |
|
|
72 |
my $arg = {@_}; |
my $arg = shift; |
73 |
|
|
74 |
carp "run needs 'dsn' to connect to (e.g. dsn => 'DBI:Pg:dbname=test')" unless ($arg->{'dsn'}); |
print Dumper($arg); |
75 |
carp "run needs 'mount' as mountpoint" unless ($arg->{'mount'}); |
|
76 |
|
carp "mount needs 'dsn' to connect to (e.g. dsn => 'DBI:Pg:dbname=test')" unless ($arg->{'dsn'}); |
77 |
|
carp "mount needs 'mount' as mountpoint" unless ($arg->{'mount'}); |
78 |
|
|
79 |
foreach (qw(filenames read update)) { |
foreach (qw(filenames read update)) { |
80 |
carp "run needs '$_' SQL" unless ($arg->{$_}); |
carp "mount needs '$_' SQL" unless ($arg->{$_}); |
81 |
} |
} |
82 |
|
|
83 |
$dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, { AutoCommit => 0 }) || die $DBI::errstr; |
$dbh = DBI->connect($arg->{'dsn'},$arg->{'user'},$arg->{'password'}, { AutoCommit => 0 }) || die $DBI::errstr; |
94 |
|
|
95 |
read_filenames; |
read_filenames; |
96 |
|
|
97 |
Fuse::main( |
$self->{'proc'} = Proc::Simple->new(); |
98 |
mountpoint=>$arg->{'mount'}, |
$self->{'proc'}->kill_on_destroy(1); |
99 |
getattr=>\&e_getattr, |
|
100 |
getdir=>\&e_getdir, |
$self->{'proc'}->start( sub { |
101 |
open=>\&e_open, |
Fuse::main( |
102 |
statfs=>\&e_statfs, |
mountpoint=>$arg->{'mount'}, |
103 |
read=>\&e_read, |
getattr=>\&e_getattr, |
104 |
write=>\&e_write, |
getdir=>\&e_getdir, |
105 |
utime=>\&e_utime, |
open=>\&e_open, |
106 |
truncate=>\&e_truncate, |
statfs=>\&e_statfs, |
107 |
debug=>0, |
read=>\&e_read, |
108 |
); |
write=>\&e_write, |
109 |
|
utime=>\&e_utime, |
110 |
|
truncate=>\&e_truncate, |
111 |
|
debug=>0, |
112 |
|
); |
113 |
|
} ); |
114 |
|
|
115 |
|
$self ? return $self : return undef; |
116 |
}; |
}; |
117 |
|
|
118 |
|
=head2 umount |
119 |
|
|
120 |
|
Unmount your database as filesystem. |
121 |
|
|
122 |
|
$mnt->umount; |
123 |
|
|
124 |
|
This will also kill background process which is translating |
125 |
|
database to filesystem. |
126 |
|
|
127 |
|
=cut |
128 |
|
|
129 |
|
sub umount { |
130 |
|
my $self = shift; |
131 |
|
|
132 |
|
confess "no process running?" unless ($self->{'proc'}); |
133 |
|
$self->{'proc'}->kill; |
134 |
|
} |
135 |
|
|
136 |
|
|
137 |
my %files; |
my %files; |
138 |
my %dirs; |
my %dirs; |
139 |
|
|
140 |
sub read_filenames { |
sub read_filenames { |
141 |
|
my $self = shift; |
142 |
|
|
143 |
# create empty filesystem |
# create empty filesystem |
144 |
(%files) = ( |
(%files) = ( |
145 |
'.' => { |
'.' => { |