my $basedir=undef;
my $dbpath=undef;
my $list=0;
+my $init=0;
my @extensions=qw(mp3 flac ogg);
my $files_pruned;
);
usage() if(!@ARGV || !$optret || $help);
+$init=1 unless($list);
if(@ARGV > 1 && !defined($basedir))
{
die("$me: --basedir must be specified if multiple paths are supplied\n");
}
-my $db=ID3FS::DB->new($me, $dbpath, $basedir, $ARGV[0]);
+my $db=ID3FS::DB->new($me, $verbose, $init, $dbpath, $basedir, $ARGV[0]);
+exit unless($db);
+
if($list)
{
list_tags($db);
}
}
-
-
-
sub list_tags
{
my($db)=@_;
bless($self,$class);
$self->{me}=shift;
- $self->{dbpath}=shift;
+ $self->{verbose}=shift;
+ my $init=shift;
+ my $dbpath=shift;
$self->{base}=shift;
- $self->{fallbackdir}=shift;
+ my $fallbackdir=shift;
- if(!defined($self->{base}) &&
- defined($self->{fallbackdir}) &&
- -d $self->{fallbackdir})
- {
- $self->{base}=$self->{fallbackdir};
- }
- $self->{dbpath}="$self->{base}/$dbfile" unless(defined($self->{dbpath}));
+ $dbpath=$self->find_db($init, $dbpath, $fallbackdir);
+ return undef unless($dbpath);
$self->{absbase}=Cwd::abs_path($self->{base});
- my $connectstr="dbi:SQLite:dbname=$self->{dbpath}";
+ my $connectstr="dbi:SQLite:dbname=$dbpath";
my ($user, $pass)=("", "");
if($self->{postgres})
{
$user="ianb";
$pass="foo";
}
- my $exists=-f $self->{dbpath};
+ my $exists=-f $dbpath;
$self->{dbh}=DBI->connect($connectstr, $user, $pass,
{ AutoCommit=>1 } );
unless(defined($self->{dbh}))
return $self;
}
+sub find_db
+{
+ my($self, $init, $dbpath, $fallbackdir)=@_;
+ my $file=undef;
+ my $base=undef;
+ if(defined($dbpath))
+ {
+ $file=$dbpath;
+ }
+ if(defined ($self->{base}))
+ {
+ $file="$self->{base}/$dbfile" unless defined($file);
+ $base=$self->{base};
+ }
+ elsif(defined($fallbackdir) && -d $fallbackdir)
+ {
+ my $path=Cwd::abs_path($fallbackdir);
+ do
+ {
+ $file="$path/$dbfile";
+ $base=$path;
+ $path=~s/(.*)\/.*/$1/;
+ }
+ while(! -f $file && length($path) && -d $path);
+ if(! -f $file)
+ {
+ $file="$fallbackdir/$dbfile";
+ $base=$fallbackdir;
+ }
+ }
+ if(!-f $file && !$init)
+ {
+ print "$self->{me}: db not found at $file\n";
+ return undef;
+ }
+ $self->{base}=$base;
+ return $file;
+}
+
sub create
{
my($self,$name)=@_;
my $source=shift;
my $mountpoint=shift;
-my $db=ID3FS::DB->new($me, $dbpath, $source);
+my $db=ID3FS::DB->new($me, $verbose, 0, $dbpath, $source);
+exit unless($db);
+
my $fuse=ID3FS::Fuse->new($db, $source, $mountpoint, $verbose);
$fuse->run();