@@ -85,6 +85,8 @@ use warnings;
8585
8686use vars qw( @ISA $imp_data_size ) ;
8787
88+ use Carp;
89+
8890@DBD::File::dr::ISA = qw( DBI::DBD::SqlEngine::dr ) ;
8991$DBD::File::dr::imp_data_size = 0;
9092
@@ -100,6 +102,31 @@ sub dsn_quote
100102# XXX rewrite using TableConfig ...
101103sub default_table_source { " DBD::File::TableSource::FileSystem" }
102104
105+ sub connect
106+ {
107+ my ($drh , $dbname , $user , $auth , $attr ) = @_ ;
108+
109+ # We do not (yet) care about conflicting attributes here
110+ # my $dbh = DBI->connect ("dbi:CSV:f_dir=test", undef, undef, { f_dir => "text" });
111+ # will test here that both test and text should exist
112+ if (my $attr_hash = (DBI-> parse_dsn ($dbname ))[3]) {
113+ if (defined $attr_hash -> {f_dir } && ! -d $attr_hash -> {f_dir }) {
114+ my $msg = " No such directory '$attr_hash ->{f_dir}" ;
115+ $drh -> set_err (2, $msg );
116+ $attr_hash -> {RaiseError } and croak $msg ;
117+ return ;
118+ }
119+ }
120+ if ($attr and defined $attr -> {f_dir } && ! -d $attr -> {f_dir }) {
121+ my $msg = " No such directory '$attr ->{f_dir}" ;
122+ $drh -> set_err (2, $msg );
123+ $attr -> {RaiseError } and croak $msg ;
124+ return ;
125+ }
126+
127+ return $drh -> SUPER::connect ($dbname , $user , $auth , $attr );
128+ } # connect
129+
103130sub disconnect_all
104131{
105132 } # disconnect_all
@@ -130,7 +157,7 @@ sub data_sources
130157{
131158 my ($dbh , $attr , @other ) = @_ ;
132159 ref ($attr ) eq " HASH" or $attr = {};
133- exists $attr -> {f_dir } or $attr -> {f_dir } = $dbh -> {f_dir };
160+ exists $attr -> {f_dir } or $attr -> {f_dir } = $dbh -> {f_dir };
134161 exists $attr -> {f_dir_search } or $attr -> {f_dir_search } = $dbh -> {f_dir_search };
135162 return $dbh -> SUPER::data_sources ($attr , @other );
136163 } # data_source
@@ -343,6 +370,10 @@ sub data_sources
343370 ? $attr -> {f_dir }
344371 : File::Spec-> curdir ();
345372 defined $dir or return ; # Stream-based databases do not have f_dir
373+ unless (-d $dir && -r $dir && -x $dir ) {
374+ $drh -> set_err ($DBI::stderr , " Cannot use directory $dir from f_dir" );
375+ return ;
376+ }
346377 my %attrs ;
347378 $attr and %attrs = %$attr ;
348379 delete $attrs {f_dir };
0 commit comments