Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Correctly uninstall short name lookup entries
The files in a repository's short/ directory contain the ids of distributions
that provide a given short-name. When uninstalling a distribution we may not
simply delete those files as other distributions may provide the same names.
Instead filter the lists.
  • Loading branch information
niner committed Feb 16, 2016
1 parent ba22b31 commit 6c44df4
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/core/CompUnit/Repository/Installation.pm
Expand Up @@ -104,6 +104,23 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
$lookup.close;
}

method !remove-dist-from-short-name-lookup-files($dist) {
my $short-dir = $.prefix.child('short');
return unless $short-dir.e;

my $id = $dist.id;

for $short-dir.dir -> $file {
my $filtered = ($file.lines $id);
if $filtered.elems > 0 {
$file.spurt: $filtered.keys.sort.map({"$_\n"}).join('');
}
else {
$file.unlink;
}
}
}

method !file-id(Str $name, Str $dist-id) {
my $id = $name ~ $dist-id;
nqp::sha1($id)
Expand Down Expand Up @@ -216,12 +233,10 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
my $sources-dir = self.prefix.child('sources');
my $resources-dir = self.prefix.child('resources');
my $bin-dir = self.prefix.child('bin');
my $short-dir = self.prefix.child('short');
my $dist-dir = self.prefix.child('dist');

$short-dir.child(nqp::sha1($_.value)).unlink for %files.grep: {$_.key ~~ /^bin\//};
$short-dir.child(nqp::sha1($_)).unlink for %provides.keys;
$short-dir.child(nqp::sha1($dist.name)).unlink;
self!remove-dist-from-short-name-lookup-files($dist);
$bin-dir.child($_.value).unlink for %files.grep: {$_.key ~~ /^bin\//};
$sources-dir.child($_).unlink for %provides.map(*.value<pm><file>);
$resources-dir.child($_).unlink for %files.values;
$dist-dir.child($dist.id).unlink;
Expand Down

0 comments on commit 6c44df4

Please sign in to comment.