Skip to content

Commit

Permalink
Delete extensions from doc root when deleted from mirror.
Browse files Browse the repository at this point in the history
Closes #8.
  • Loading branch information
theory committed May 21, 2011
1 parent 6aeb23f commit fd621aa
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Changes
Expand Up @@ -3,6 +3,9 @@ Revision history for Perl extension PGXN::API
0.15.1
- Eliminated "Use of uninitialized value in subroutine entry" warning
when indexing a user with no associated URI.
- If an version of an extension is deleted from the mirror extension
JSON file, it will now also be deleted from the API doc root's
extension JSON file (Issue #8).

0.15.0 2011-05-12T18:40:43
- Changed the JSONP callback parameter from "jsonp" to "callback".
Expand Down
9 changes: 8 additions & 1 deletion lib/PGXN/API/Indexer.pm
Expand Up @@ -388,7 +388,8 @@ sub update_extensions {

# Copy the version info from the doc to the mirror and add the date.
my $version = $data->{version};
my $mir_dists = $mir_meta->{versions}{$version};
my $mir_vers = $mir_meta->{versions};
my $mir_dists = $mir_vers->{$version};
my $doc_dists = $doc_meta->{versions}{$version} ||= [];

# Copy the doc root versions.
Expand All @@ -414,6 +415,12 @@ sub update_extensions {
}
}

# Remove any deleted versions.
my $ddvers = $doc_meta->{versions};
for my $v (keys %{ $ddvers }) {
delete $ddvers->{$v} unless $mir_vers->{$v};
}

# Write it back out and index it.
$api->write_json_to($doc_file => $mir_meta);
$self->_index(extensions => {
Expand Down
18 changes: 18 additions & 0 deletions t/data/pair-ext-updated4.json
@@ -0,0 +1,18 @@
{
"extension": "pair",
"latest": "stable",
"stable": { "dist": "pair", "version": "0.1.3", "sha1": "cebefd23151b4b797239646f7ae045b03d028fcf" },
"testing": { "dist": "pair", "version": "0.1.1", "sha1": "c552c961400253e852250c5d2f3def183c81adb3" },
"versions": {
"0.1.3": [
{ "dist": "pair", "version": "0.1.2" }
],
"0.1.1": [
{ "dist": "otherdist", "version": "0.3.0" },
{ "dist": "pair", "version": "0.1.1" }
],
"0.1.0": [
{ "dist": "pair", "version": "0.1.0" }
]
}
}
32 changes: 28 additions & 4 deletions t/indexer.t
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 239;
use Test::More tests => 243;
#use Test::More 'no_plan';
use File::Copy::Recursive qw(dircopy fcopy);
use File::Path qw(remove_tree);
Expand Down Expand Up @@ -545,9 +545,9 @@ $exp = {
versions => {
'0.1.0' => [
{
dist => 'pair',
date => '2010-10-18T15:24:21Z',
version => '0.1.0',
dist => 'pair',
date => '2010-10-18T15:24:21Z',
version => '0.1.0',
},
],
},
Expand Down Expand Up @@ -656,8 +656,32 @@ $exp->{versions}{'0.1.2'} = [{
}];
ok $doc_data = $api->read_json_from($ext_file),
'Read the doc root extension data file one more time';
is_deeply $doc_data, $exp, 'Should now have the 0.1.2 metadata';

# Now a reindex where a version disappears.
fcopy catfile(qw(t data pair-ext-updated4.json)),
catfile($api->mirror_root, qw(extension pair.json));
$meta_012->{provides}{pair}{version} = '0.1.3';
$params->{meta} = $meta_012;
ok $indexer->update_extensions($params), 'Replace 0.1.2 with 0.1.3';
ok $doc_data = $api->read_json_from($ext_file),
'Read the doc root extension data file one more time';
$exp->{stable}{version} = '0.1.3';
$exp->{versions}{'0.1.3'} = delete $exp->{versions}{'0.1.2'};
is_deeply $doc_data, $exp, 'Should now have the 0.1.3 metadata';

is_deeply shift @{ $indexer->to_index->{extensions} }, {
abstract => 'A key/value pair dåtå type',
date => '2010-11-10T12:18:03Z',
dist => 'pair',
docpath => '',
extension => 'pair',
key => 'pair',
user => 'theory',
user_name => 'David E. Wheeler',
version => '0.1.3',
}, 'Should have extension index data again';

##############################################################################
# Test parse_docs().
my $sync = PGXN::API::Sync->new(
Expand Down

0 comments on commit fd621aa

Please sign in to comment.