line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/local/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package DBI::Shell::FindSqlFile; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '11.97'; # VERSION |
6
|
|
|
|
|
|
|
|
7
|
7
|
|
|
7
|
|
54
|
use strict; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
214
|
|
8
|
7
|
|
|
7
|
|
35
|
use File::Find (); |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
114
|
|
9
|
7
|
|
|
7
|
|
34
|
use File::Basename; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
864
|
|
10
|
7
|
|
|
7
|
|
63
|
use File::Spec; |
|
7
|
|
|
|
|
13
|
|
|
7
|
|
|
|
|
222
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# Set the variable $File::Find::dont_use_nlink if you're using AFS, |
13
|
|
|
|
|
|
|
# since AFS cheats. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# for the convenience of &wanted calls, including -eval statements: |
16
|
7
|
|
|
7
|
|
37
|
use vars qw/*name *dir *prune @found $to_find_file $debug/; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
3805
|
|
17
|
|
|
|
|
|
|
*name = *File::Find::name; |
18
|
|
|
|
|
|
|
*dir = *File::Find::dir; |
19
|
|
|
|
|
|
|
*prune = *File::Find::prune; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
@found = (); |
22
|
|
|
|
|
|
|
$to_find_file = undef; |
23
|
|
|
|
|
|
|
$debug = 0; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub look_for_file { |
26
|
8
|
|
|
8
|
0
|
24
|
my $self = shift; |
27
|
8
|
|
|
|
|
16
|
my $file = shift; |
28
|
8
|
|
|
|
|
504
|
my ($base, $dir, $ext) = fileparse($file,'\..*?'); |
29
|
|
|
|
|
|
|
|
30
|
8
|
|
|
|
|
38
|
$debug = $self->{debug}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# print "file $file : concat $dir$base$ext\n"; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Work-around to fileparse adding current directory. |
35
|
8
|
50
|
|
|
|
45
|
$dir = undef unless ( $file eq "$dir$base$ext" ); |
36
|
|
|
|
|
|
|
|
37
|
8
|
50
|
|
|
|
31
|
unless ($ext) { |
38
|
0
|
|
|
|
|
0
|
$ext = q{.sql}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
# If a directory is defined, return to caller |
41
|
8
|
50
|
|
|
|
27
|
if ($dir) { |
42
|
0
|
|
|
|
|
0
|
return ( "$dir$base$ext" ); |
43
|
|
|
|
|
|
|
}; |
44
|
|
|
|
|
|
|
|
45
|
8
|
|
|
|
|
23
|
$to_find_file = qq{$base$ext}; |
46
|
|
|
|
|
|
|
|
47
|
8
|
50
|
|
|
|
25
|
$self->log("calling find with $to_find_file") if $self->{debug}; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# Split the sqlpath, then determine if any of the directories are valid. |
51
|
14
|
100
|
|
|
|
305
|
my @search_path = map { -d $_ ? $_ : () } split(/:/, |
52
|
|
|
|
|
|
|
defined $self->{sqlpath} ? $self->{sqlpath} : () |
53
|
8
|
50
|
|
|
|
68
|
); |
54
|
|
|
|
|
|
|
# , (exists $ENV{DBISH_SQL_PATH} ? $ENV{DBISH_SQL_PATH} : ()) ); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$self->log( "search path: " . join( "\n", @search_path ) ) |
57
|
8
|
50
|
|
|
|
42
|
if $self->{debug}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Traverse desired filesystems |
60
|
8
|
|
|
|
|
952
|
File::Find::find( |
61
|
|
|
|
|
|
|
{ |
62
|
|
|
|
|
|
|
wanted => \&wanted |
63
|
|
|
|
|
|
|
, no_chdir => 1 |
64
|
|
|
|
|
|
|
, bydepth => 0 |
65
|
|
|
|
|
|
|
}, |
66
|
|
|
|
|
|
|
@search_path); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
8
|
50
|
|
|
|
91
|
return shift @found if @found; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
return; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub wanted { |
75
|
208
|
50
|
0
|
208
|
0
|
664
|
(/^.*$to_find_file\z/is && print "Found $to_find_file file |
76
|
|
|
|
|
|
|
$name\n" ) if $debug; |
77
|
208
|
100
|
|
|
|
824
|
/^.*$to_find_file\z/is && push @found, $name; |
78
|
208
|
100
|
66
|
|
|
7994
|
$prune = 1 if ( -d $dir and -d $name and $dir ne $name ); |
|
|
|
100
|
|
|
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |