From b71e097946315daf91860bc4ca90ad4eb6e0ab91 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Tue, 23 Nov 2004 23:54:58 +0000 Subject: [PATCH] API 0.07: - added is_mounted - mount will now block until filesystem is mounted (this might take up to 2 sec in intervals of 0.5 sec) git-svn-id: svn://svn.rot13.org/fuse_dbi/trunk@47 17f4e80c-d0e0-0310-8903-bfc3ae804c12 --- DBI.pm | 62 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/DBI.pm b/DBI.pm index c8572ce..c360e3c 100755 --- a/DBI.pm +++ b/DBI.pm @@ -13,7 +13,7 @@ use Carp; use Data::Dumper; -our $VERSION = '0.06'; +our $VERSION = '0.07'; =head1 NAME @@ -152,7 +152,16 @@ sub mount { die "fork() failed: $!" unless defined $pid; # child will return to caller if ($pid) { - return $self; + my $counter = 4; + while ($counter && ! $self->is_mounted) { + select(undef, undef, undef, 0.5); + $counter--; + } + if ($self->is_mounted) { + return $self; + } else { + return undef; + } } } @@ -192,6 +201,32 @@ sub mount { }; +=head2 is_mounted + +Check if fuse filesystem is mounted + + if ($mnt->is_mounted) { ... } + +=cut + +sub is_mounted { + my $self = shift; + + my $mounted = 0; + my $mount = $self->{'mount'} || confess "can't find mount point!"; + if (open(MTAB, "/etc/mtab")) { + while() { + $mounted = 1 if (/ $mount fuse /i); + } + close(MTAB); + } else { + warn "can't open /etc/mtab: $!"; + } + + return $mounted; +} + + =head2 umount Unmount your database as filesystem. @@ -206,25 +241,12 @@ database to filesystem. sub umount { my $self = shift; - if ($self->{'mount'}) { - if (open(MTAB, "/etc/mtab")) { - my $mounted = 0; - my $mount = $self->{'mount'}; - while() { - $mounted = 1 if (/ $mount fuse /i); - } - close(MTAB); - - if ($mounted) { - system "fusermount -u ".$self->{'mount'}." 2>&1 >/dev/null" || return 0; - return 1; - } - - } else { - warn "can't open /etc/mtab: $!"; - return 0; - } + if ($self->{'mount'} && $self->is_mounted) { + system "fusermount -u ".$self->{'mount'}." 2>&1 >/dev/null" || return 0; + return 1; } + + return 0; } $SIG{'INT'} = sub { -- 2.20.1