Skip to content

Commit

Permalink
Change to sid-dir, move need-repo to CUR
Browse files Browse the repository at this point in the history
  • Loading branch information
MadcapJake committed May 2, 2016
1 parent 669a9cd commit 4f1ef9c
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
13 changes: 10 additions & 3 deletions src/core/CompUnit/Repository.pm
@@ -1,4 +1,4 @@
class CompUnit::RepositorySpecification { ... }
# class CompUnit::RepositorySpecification { ... }

This comment has been minimized.

Copy link
@MadcapJake

MadcapJake May 2, 2016

Author Owner

Not really sure where these stubs are supposed to go.

role CompUnit::Repository {
has CompUnit::Repository $.next-repo is rw;

Expand All @@ -12,9 +12,16 @@ role CompUnit::Repository {
returns CompUnit:D
{ ... }

# Resolves a repository specification to a repository class. The default
# implementation passes the buck or returns CURU. CURUs are handled
# specially within CompUnit::RepositoryRegistry.setup-repositories.
method need-repository(CompUnit::RepositorySpecification $spec)
returns CompUnit::Repository:D
{ ... }
returns CompUnit::Repository:U
{
return self.next-repo.need-repository($spec) if self.next-repo;
CompUnit::Repository::Unknown
}


# Resolves a dependency specification to a concrete dependency.
# Returns a CompUnit object that represents the selected dependency.
Expand Down
5 changes: 0 additions & 5 deletions src/core/CompUnit/Repository/AbsolutePath.pm
Expand Up @@ -9,11 +9,6 @@ class CompUnit::Repository::AbsolutePath does CompUnit::Repository {
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
}

method need-repository(CompUnit::RepositorySpecification $spec) {
return self.next-repo.need-repository($spec) if self.next-repo;
CompUnit::Repository::Unknown
}

method load(IO::Path:D $file) returns CompUnit:D {
if $file.is-absolute {

Expand Down
19 changes: 16 additions & 3 deletions src/core/CompUnit/Repository/Installation.pm
Expand Up @@ -127,6 +127,14 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
}
}

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

my $id = $dist.id
for $sid-dir.dir -> $dir { $dir.child($id).unlink }
}

method !file-id(Str $name, Str $dist-id) {
my $id = $name ~ $dist-id;
nqp::sha1($id)
Expand Down Expand Up @@ -211,8 +219,12 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
}

for %repositories.kv -> $short-id, $name {
my $destination = $repositories-dir.child($short-id);
$destination.spurt($name, :createonly)
my $repo-dir = $.prefix.child('repositories');
$repo-dir.mkdir unless $repo-dir.e;
my $sid-dir = $repo-dir.child($short-id);
$sid-dir.mkdir unless $sid-dir.e;
$sid-dir.child($dist-id).spurt:
"{$dist.ver // ''}\n{$dist.auth // ''}\n{$dist.api // ''}\n"
}

$dist-dir.child($dist-id).spurt: to-json($dist.Hash);
Expand Down Expand Up @@ -275,10 +287,10 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
my $dist-dir = self.prefix.child('dist');

self!remove-dist-from-short-name-lookup-files($dist);
self!remove-repo-from-short-id-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;
$repositories-dir.child($_).unlink for %repositories.keys;
$dist-dir.child($dist.id).unlink;
}

Expand Down Expand Up @@ -400,6 +412,7 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {

method need-repository(CompUnit::RepositorySpecification $spec) {
my $repository = $.prefix.child('repositories').child($spec.short-id);
# TODO: Need some way to decide on which repo inside the sid-dir to pick
return self.need(CompUnit::DependencySpecification(short-name => $repository.slurp))
if $repository.e;
return self.next-repo.need-repository($spec) if self.next-repo;
Expand Down
6 changes: 0 additions & 6 deletions src/core/CompUnit/Repository/NQP.pm
Expand Up @@ -21,12 +21,6 @@ class CompUnit::Repository::NQP does CompUnit::Repository {
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
}

method need-repository(CompUnit::RepositorySpecification $spec) {
# TODO: Implement if possible
return self.next-repo.need-repository($spec) if self.next-repo;
CompUnit::Repository::Unknown
}

method loaded() {
[]
}
Expand Down
6 changes: 0 additions & 6 deletions src/core/CompUnit/Repository/Perl5.pm
Expand Up @@ -35,12 +35,6 @@ class CompUnit::Repository::Perl5 does CompUnit::Repository {
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
}

method need-repository(CompUnit::RepositorySpecification $spec) {
# TODO: Implement if possible
return self.next-repo.need-repository($spec) if self.next-repo;
CompUnit::Repository::Unknown
}

method loaded() {
[]
}
Expand Down
5 changes: 0 additions & 5 deletions src/core/CompUnit/Repository/Unknown.pm
Expand Up @@ -13,11 +13,6 @@ class CompUnit::Repository::Unknown does CompUnit::Repository {
X::CompUnit::UnsatisfiedDependency.new(:specification($spec)).throw;
}

method need-repository(CompUnit::RepositorySpecification $spec) {
return self.next-repo.need-repository($spec) if self.next-repo;
CompUnit::Repository::Unknown
}

# Returns empty array as CURUs cannot return CUs
method loaded()
returns Iterable
Expand Down
3 changes: 1 addition & 2 deletions src/core/CompUnit/RepositoryRegistry.pm
Expand Up @@ -4,7 +4,6 @@ class CompUnit::Repository::AbsolutePath { ... }
class CompUnit::Repository::NQP { ... }
class CompUnit::Repository::Perl5 { ... }
class CompUnit::Repository::Unknown { ... }
use nqp;
class CompUnit::RepositoryRegistry {
my $lock = Lock.new;

Expand Down Expand Up @@ -171,7 +170,7 @@ class CompUnit::RepositoryRegistry {
unless $repo.isa(CompUnit::Repository::Unknown) {
# rebind resolved CUR to $repos
# XXX: Relying on path-spec seems risky
nqp::bindkey($repos, $repo.path-spec, $repo)
nqp::bindkey($repos, $repo.path-spec, $repo);
# remove from $curus
$curus := nqp::splice($curus, nqp::list(), $cursor, 1);
# mark that a new repo has been added
Expand Down

0 comments on commit 4f1ef9c

Please sign in to comment.