From b04ff786fc190a934e48ed34ea26a1507625e5e3 Mon Sep 17 00:00:00 2001 From: Kenichi Ishigaki Date: Wed, 15 Apr 2009 20:31:17 +0000 Subject: [PATCH] DBD-SQLite: unicode dirs/files may not be removed by CLEANUP of File::Temp (as they may requrie special treatment on Win32) --- lib/DBD/SQLite.pm | 5 +++-- t/33_non_latin_path.t | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm index 053c895..63820c6 100644 --- a/lib/DBD/SQLite.pm +++ b/lib/DBD/SQLite.pm @@ -69,9 +69,10 @@ sub connect { require Win32; require File::Basename; my ($file, $dir, $suffix) = File::Basename::fileparse($real); - if ( -f $real ) { + my $short = Win32::GetShortPathName($real); + if ( $short && -f $short ) { # Existing files will work directly. - $real = Win32::GetShortPathName($real); + $real = short; } elsif ( -d $dir ) { # We are creating a new file. # Does the directory it's in at least exist? diff --git a/t/33_non_latin_path.t b/t/33_non_latin_path.t index 8f43ea5..c29f61f 100644 --- a/t/33_non_latin_path.t +++ b/t/33_non_latin_path.t @@ -47,7 +47,7 @@ foreach my $subdir ( 'longascii', 'adatb }; is( $@, '', "Could connect to database in $subdir" ); diag( $@ ) if $@; - unlink($dbfile) if -e $dbfile; + unlink(_path($dbfile)) if -e _path($dbfile); # Repeat with the unicode flag on my $ufile = $dbfile; @@ -61,6 +61,7 @@ foreach my $subdir ( 'longascii', 'adatb }; is( $@, '', "Could connect to database in $subdir" ); diag( $@ ) if $@; + unlink(_path($ufile)) if -e _path($ufile); # when the name of the database file has non-latin characters my $dbfilex = catfile($dir, "$subdir.db"); @@ -68,4 +69,23 @@ foreach my $subdir ( 'longascii', 'adatb DBI->connect("dbi:SQLite:dbname=$dbfilex", "", "", {RaiseError => 1, PrintError => 0}); }; ok(!$@, "Could connect to database in $dbfilex") or diag $@; + unlink(_path($dbfilex)) if -e _path($dbfilex); } + +sub _path { # copied from DBD::SQLite::connect + my $path = shift; + return $path unless $^O eq 'MSWin32'; + + require Win32; + require File::Basename; + + my ($file, $dir, $suffix) = File::Basename::fileparse($path); + my $short = Win32::GetShortPathName($path); + if ( $short && -f $short ) { + # Existing files will work directly. + return $short; + } elsif ( -d $dir ) { + return join '', grep { defined } Win32::GetShortPathName($dir), $file, $suffix; + } + return $path; +} \ No newline at end of file