line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Search for our Unix signature in text and binary files |
3
|
|
|
|
|
|
|
# and replace it with the real prefix ($Config{prefix} by default). |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
package PPM::RelocPerl; |
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
@EXPORT = qw(RelocPerl); |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
9
|
use File::Find; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
113
|
|
12
|
2
|
|
|
2
|
|
9
|
use Config; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
13
|
2
|
|
|
2
|
|
7
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
57
|
|
14
|
2
|
|
|
2
|
|
6
|
use vars qw( $VERSION ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
858
|
|
15
|
|
|
|
|
|
|
$VERSION = '0.01_01'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# We have to build up this variable, otherwise |
18
|
|
|
|
|
|
|
# PPM will mash it when it upgrades itself. |
19
|
|
|
|
|
|
|
my $frompath_default |
20
|
|
|
|
|
|
|
= '/tmp' . '/.ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZpErLZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZperl' |
21
|
|
|
|
|
|
|
; |
22
|
|
|
|
|
|
|
my ($topath, $frompath); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub wanted { |
25
|
0
|
0
|
0
|
0
|
0
|
|
if (-l) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
return; # do nothing for symlinks |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
elsif (-B) { |
29
|
0
|
|
|
|
|
|
check_for_frompath($_, 1); # binary file edit |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif (-e && -s && -f) { |
32
|
0
|
|
|
|
|
|
check_for_frompath($_, 0); # text file edit |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub check_for_frompath { |
37
|
0
|
|
|
0
|
0
|
|
my ($file, $binmode) = @_; |
38
|
0
|
|
|
|
|
|
local(*F, $_); |
39
|
0
|
0
|
|
|
|
|
open(F, "<$file") or die "Can't open `$file': $!"; |
40
|
0
|
0
|
|
|
|
|
binmode F if $binmode; |
41
|
0
|
|
|
|
|
|
while () { |
42
|
0
|
0
|
|
|
|
|
if (/\Q$frompath\E/o) { |
43
|
0
|
|
|
|
|
|
close F; |
44
|
0
|
|
|
|
|
|
edit_it($file, $binmode); |
45
|
0
|
|
|
|
|
|
last; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
# implicit close of F; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub edit_it |
52
|
|
|
|
|
|
|
{ |
53
|
0
|
|
|
0
|
0
|
|
my ($file, $binmode) = @_; |
54
|
0
|
|
|
|
|
|
my $nullpad = length($frompath) - length($topath); |
55
|
0
|
|
|
|
|
|
$nullpad = "\0" x $nullpad; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
local $/; |
58
|
|
|
|
|
|
|
# Force the file to be writable |
59
|
0
|
|
|
|
|
|
my $mode = (stat($file))[2] & 07777; |
60
|
0
|
|
|
|
|
|
chmod $mode | 0222, $file; |
61
|
0
|
0
|
|
|
|
|
open(F, "+<$file") or die "Couldn't open $file: $!"; |
62
|
0
|
0
|
|
|
|
|
binmode(F) if $binmode; |
63
|
0
|
|
|
|
|
|
my $dat = ; |
64
|
0
|
0
|
|
|
|
|
if ($binmode) { |
65
|
0
|
|
|
|
|
|
$dat =~ s|\Q$frompath\E(.*?)\0|$topath$1$nullpad\0|gs; |
66
|
|
|
|
|
|
|
} else { |
67
|
0
|
|
|
|
|
|
$dat =~ s|\Q$frompath\E|$topath|gs; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
0
|
|
|
|
|
seek(F, 0, 0) or die "Couldn't seek on $file: $!"; |
70
|
0
|
|
|
|
|
|
print F $dat; |
71
|
0
|
|
|
|
|
|
close(F); |
72
|
|
|
|
|
|
|
# Restore the permissions |
73
|
0
|
|
|
|
|
|
chmod $mode, $file; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub RelocPerl |
77
|
|
|
|
|
|
|
{ |
78
|
0
|
|
|
0
|
0
|
|
my ($dir, $opt_topath, $opt_frompath) = @_; |
79
|
0
|
0
|
|
|
|
|
$topath = defined $opt_topath ? $opt_topath : $Config{'prefix'}; |
80
|
0
|
0
|
|
|
|
|
$frompath = defined $opt_frompath ? $opt_frompath : $frompath_default; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
find(\&wanted, $dir); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |