line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package File::Slurp::Remote::SmartOpen; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
53
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
1
|
|
|
1
|
|
8
|
use File::Slurp::Remote::BrokenDNS qw($myfqdn %fqdnify); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
129
|
|
8
|
1
|
|
|
1
|
|
18
|
use Tie::Function::Examples qw(%q_shell); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
151
|
|
9
|
1
|
|
|
1
|
|
6
|
use Carp qw(confess); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1107
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @EXPORT = qw(smartopen); |
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
our $ssh = "ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o PasswordAuthentication=no"; |
14
|
|
|
|
|
|
|
our $VERSION = 0.2; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub smartopen($\$$) |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
0
|
0
|
|
my ($file, $fdref, $mode) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
my $unzip = ''; |
21
|
0
|
|
|
|
|
|
my $zip = ''; |
22
|
0
|
0
|
|
|
|
|
if ($file =~ /\.gz$/) { |
|
|
0
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$unzip = "zcat"; |
24
|
0
|
|
|
|
|
|
$zip = "gzip"; |
25
|
|
|
|
|
|
|
} elsif ($file =~ /\.bz2$/) { |
26
|
0
|
|
|
|
|
|
$unzip = "bzcat"; |
27
|
0
|
|
|
|
|
|
$zip = "bzip2"; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my $pid; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $fd = $$fdref; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
0
|
|
|
|
if ($file =~ s/(.+):// && $fqdnify{$1} ne $myfqdn) { |
35
|
0
|
|
|
|
|
|
my $host = $1; |
36
|
0
|
0
|
|
|
|
|
$unzip = "|$unzip" if $unzip; |
37
|
0
|
0
|
|
|
|
|
$zip = "$zip|" if $zip; |
38
|
0
|
0
|
0
|
|
|
|
if ($mode && $mode eq 'w') { |
39
|
0
|
|
|
|
|
|
my $cat = $q_shell{"cat > $q_shell{$file}"}; |
40
|
0
|
0
|
|
|
|
|
$pid = open $fd, "|$zip $ssh $q_shell{$host} $cat" |
41
|
|
|
|
|
|
|
or confess "open |$zip $ssh $q_shell{$host} $cat: $!"; |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
0
|
|
|
|
|
$pid = open $fd, "$ssh -n $q_shell{$host} cat $q_shell{$file} $unzip|" |
44
|
|
|
|
|
|
|
or confess "open $ssh $q_shell{$host} cat $q_shell{$file} $unzip|: $!"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} else { |
47
|
0
|
0
|
0
|
|
|
|
if ($mode && $mode eq 'w') { |
48
|
0
|
0
|
|
|
|
|
if ($zip) { |
49
|
0
|
0
|
|
|
|
|
$pid = open $fd, "|$zip > $q_shell{$file}" |
50
|
|
|
|
|
|
|
or die "open |$zip > $q_shell{$file}: $!"; |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
0
|
|
|
|
|
open $fd, ">", $file |
53
|
|
|
|
|
|
|
or die "open >$file: $!"; |
54
|
0
|
|
|
|
|
|
$pid = "0butTrue"; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
0
|
|
|
|
|
if ($unzip) { |
58
|
0
|
0
|
|
|
|
|
$pid = open $fd, "$unzip < $q_shell{$file}|" |
59
|
|
|
|
|
|
|
or die "open $unzip < $q_shell{$file}|: $!"; |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
0
|
|
|
|
|
open $fd, "<", $file |
62
|
|
|
|
|
|
|
or die "open <$file: $!"; |
63
|
0
|
|
|
|
|
|
$pid = "0buttrue"; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
0
|
|
|
|
|
|
$$fdref = $fd; |
68
|
0
|
|
|
|
|
|
return $pid; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
__END__ |