From: Peter Rabbitson Date: Wed, 2 Jun 2010 11:22:20 +0000 (+0000) Subject: Make sure ddl_dir is created even if a dir-object is supplied X-Git-Tag: v0.08122~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=076be7c46559c6c27b70946893e2f82d1ff4e0a0;p=dbsrgits%2FDBIx-Class.git Make sure ddl_dir is created even if a dir-object is supplied --- diff --git a/Changes b/Changes index 246036e..f3b4859 100644 --- a/Changes +++ b/Changes @@ -27,6 +27,8 @@ Revision history for DBIx::Class - Sybase ASE driver now uses SET ROWCOUNT where possible, and Generic Subquery otherwise for limit support instead of always using software limit emulation + - create_ddl_dir (and derivatives) now attempt to create the given + $ddl_dir if it does not already exist * Fixes - Fix nasty potentially data-eating bug when deleting/updating diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index 17cb769..fb2a7a2 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -15,7 +15,7 @@ use Scalar::Util qw/refaddr weaken reftype blessed/; use Data::Dumper::Concise 'Dumper'; use Sub::Name 'subname'; use Try::Tiny; -use File::Path 'mkpath'; +use File::Path 'make_path'; use namespace::clean; __PACKAGE__->mk_group_accessors('simple' => qw/ @@ -2331,8 +2331,13 @@ sub create_ddl_dir { carp "No directory given, using ./\n"; $dir = './'; } else { - -d $dir or mkpath $dir - or $self->throw_exception("create_ddl_dir: $! creating dir '$dir'"); + -d $dir + or + make_path ("$dir") # make_path does not like objects (i.e. Path::Class::Dir) + or + $self->throw_exception( + "Failed to create '$dir': " . ($! || $@ || 'error unknow') + ); } $self->throw_exception ("Directory '$dir' does not exist\n") unless(-d $dir); diff --git a/t/storage/deploy.t b/t/storage/deploy.t index e6ccd2d..d2bca43 100644 --- a/t/storage/deploy.t +++ b/t/storage/deploy.t @@ -14,20 +14,20 @@ BEGIN { } use File::Spec; -use File::Path qw/ mkpath rmtree /; - +use Path::Class qw/dir/; +use File::Path qw/make_path remove_tree/; my $schema = DBICTest->init_schema(); -my $var = File::Spec->catfile(qw| t var create_ddl_dir |); +my $var = dir (qw| t var create_ddl_dir |); -d $var - or mkpath($var) - or die "can't create $var"; + or make_path( "$var" ) + or die "can't create $var: $!"; -my $test_dir_1 = File::Spec->catdir( $var, 'test1', 'foo', 'bar' ); -rmtree( $test_dir_1 ) if -d $test_dir_1; +my $test_dir_1 = $var->subdir ('test1', 'foo', 'bar' ); +remove_tree( "$test_dir_1" ) if -d $test_dir_1; $schema->create_ddl_dir( undef, undef, $test_dir_1 ); -ok( -d $test_dir_1, 'create_ddl_dir did a mkpath on its target dir' ); +ok( -d $test_dir_1, 'create_ddl_dir did a make_path on its target dir' ); ok( scalar( glob $test_dir_1.'/*.sql' ), 'there are sql files in there' ); TODO: {