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