forked from derphilipp/macportsscripts
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmacports_34482_fix.pl
executable file
·82 lines (57 loc) · 1.64 KB
/
macports_34482_fix.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env perl
# taken from https://trac.macports.org/ticket/34482
use strict;
use warnings;
sub regfiles {
my ($top,$regfile) = @_;
my $fast = 1;
my @regs;
if ($fast) {
push(@regs,"$top/local/var/macports/registry/$regfile");
}
# in case this bug ever comes up again and $regfile moves
else {
@regs = `find /opt -name '$regfile'`;
return undef unless @regs;
chomp @regs;
}
return \@regs;
}
my $sqlite3 = '/opt/local/bin/sqlite3';
die "Please do a 'port install sqlite3' and try again\n" if (! -x $sqlite3);
my $top = '/opt';
my $regfile = 'registry.db';
my $regs = regfiles($top,$regfile);
die "Unable to locate $regfile in $top\n" if (! $regs);
my $cmd;
foreach my $dbfile (@$regs) {
$cmd = "$sqlite3 $dbfile 'SELECT * FROM dependencies WHERE id NOT IN (SELECT DISTINCT id FROM ports);'";
print $cmd, "\n";
my @tofix = `$cmd`;
if (! @tofix) {
warn "Registry file $regfile format is correct...\n";
}
else {
chomp @tofix;
my $ids = {};
foreach my $entry (@tofix) {
my @parts = split /\|/, $entry;
my $id = shift @parts;
$ids->{$id} = 1;
}
foreach my $id (sort keys %$ids) {
$cmd = "$sqlite3 $dbfile 'DELETE FROM files WHERE id = $id'";
print $cmd, "\n";
system($cmd);
$cmd = "$sqlite3 $dbfile 'DELETE FROM dependencies WHERE id = $id'";
print $cmd, "\n";
system($cmd);
}
}
}
my @inactive = `port list inactive`;
if (@inactive) {
$cmd = 'port uninstall inactive';
print $cmd, "\n";
system($cmd);
}