/[fuse_dbi]/trunk/DBI.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/DBI.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 40 by dpavlin, Fri Nov 19 21:56:12 2004 UTC revision 47 by dpavlin, Tue Nov 23 23:54:58 2004 UTC
# Line 13  use Carp; Line 13  use Carp;
13  use Data::Dumper;  use Data::Dumper;
14    
15    
16  our $VERSION = '0.06';  our $VERSION = '0.07';
17    
18  =head1 NAME  =head1 NAME
19    
# Line 152  sub mount { Line 152  sub mount {
152                  die "fork() failed: $!" unless defined $pid;                  die "fork() failed: $!" unless defined $pid;
153                  # child will return to caller                  # child will return to caller
154                  if ($pid) {                  if ($pid) {
155                          return $self;                          my $counter = 4;
156                            while ($counter && ! $self->is_mounted) {
157                                    select(undef, undef, undef, 0.5);
158                                    $counter--;
159                            }
160                            if ($self->is_mounted) {
161                                    return $self;
162                            } else {
163                                    return undef;
164                            }
165                  }                  }
166          }          }
167    
# Line 192  sub mount { Line 201  sub mount {
201    
202  };  };
203    
204    =head2 is_mounted
205    
206    Check if fuse filesystem is mounted
207    
208      if ($mnt->is_mounted) { ... }
209    
210    =cut
211    
212    sub is_mounted {
213            my $self = shift;
214    
215            my $mounted = 0;
216            my $mount = $self->{'mount'} || confess "can't find mount point!";
217            if (open(MTAB, "/etc/mtab")) {
218                    while(<MTAB>) {
219                            $mounted = 1 if (/ $mount fuse /i);
220                    }
221                    close(MTAB);
222            } else {
223                    warn "can't open /etc/mtab: $!";
224            }
225    
226            return $mounted;
227    }
228    
229    
230  =head2 umount  =head2 umount
231    
232  Unmount your database as filesystem.  Unmount your database as filesystem.
# Line 206  database to filesystem. Line 241  database to filesystem.
241  sub umount {  sub umount {
242          my $self = shift;          my $self = shift;
243    
244          if ($self->{'mount'}) {          if ($self->{'mount'} && $self->is_mounted) {
245                  if (open(MTAB, "/etc/mtab")) {                  system "fusermount -u ".$self->{'mount'}." 2>&1 >/dev/null" || return 0;
246                          my $mounted = 0;                  return 1;
                         my $mount = $self->{'mount'};  
                         while(<MTAB>) {  
                                 $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;  
                 }  
247          }          }
248    
249            return 0;
250  }  }
251    
252  $SIG{'INT'} = sub {  $SIG{'INT'} = sub {

Legend:
Removed from v.40  
changed lines
  Added in v.47

  ViewVC Help
Powered by ViewVC 1.1.26