Skip to content
Permalink
Browse files

Allow an IO::Path for CUR::FileSystem

- fixes #2879
- moved the $!lock attribute from CUR::Locally to CUR::Installation
  - as it is only needed there
- added $!abspath attribute to CUR::Locally
  - as this appears to be really needed for all classes consuming CUR::Locally
  - and it is always calculated, so why not keep it then
- move cache to role lexical, lose the state (potential race condition)
  - also add a lock so that all access/changes are done by a single thread
- make $!WHICH a ValueObjAt, indicating a CUR::Locally is a value type
  • Loading branch information...
lizmat committed May 10, 2019
1 parent 1db7e4b commit e9bbefd3c30f51a61be0aa7cd8ac809ef4fa852c
Showing with 27 additions and 20 deletions.
  1. +1 −2 src/core/CompUnit/Repository/Installation.pm6
  2. +26 −18 src/core/CompUnit/Repository/Locally.pm6
@@ -1,4 +1,5 @@
class CompUnit::Repository::Installation does CompUnit::Repository::Locally does CompUnit::Repository::Installable {
has $!lock = Lock.new;
has $!cver = nqp::hllize(nqp::atkey(nqp::gethllsym('perl6', '$COMPILER_CONFIG'), 'version'));
has %!loaded; # cache compunit lookup for self.need(...)
has %!seen; # cache distribution lookup for self!matching-dist(...)
@@ -11,8 +12,6 @@ class CompUnit::Repository::Installation does CompUnit::Repository::Locally does

my $verbose = nqp::getenvhash<RAKUDO_LOG_PRECOMP>;

submethod BUILD(:$!prefix, :$!lock, :$!WHICH, :$!next-repo --> Nil) { }

my class InstalledDistribution is Distribution::Hash {
method content($address) {
my $entry = $.meta<provides>.values.first: { $_{$address}:exists };
@@ -1,38 +1,46 @@
role CompUnit::Repository::Locally {
has Lock $!lock;
has IO::Path $.prefix is required;
has Str $.WHICH;

method new(CompUnit::Repository::Locally: Str:D :$prefix, CompUnit::Repository :$next-repo, *%args) {
my $abspath := $*SPEC.rel2abs($prefix);
my $IO := $abspath.IO;

state %instances;
my $WHICH = self.^name ~ '|' ~ $abspath;
%instances{$WHICH} //=
self.bless(:prefix($IO), :lock(Lock.new), :$WHICH, :$next-repo, |%args);
has Str $.abspath;
has IO::Path $.prefix is required;
has ValueObjAt $.WHICH is required;

my $lock = Lock.new;
my %instances;

method new(CompUnit::Repository::Locally: Any:D :$prefix is copy) {

my $abspath;
if $prefix ~~ IO::Path {
$abspath := $prefix.abspath;
}
else {
$abspath := $*SPEC.rel2abs($prefix.Str);
$prefix = $abspath.IO;
}

my $WHICH := ValueObjAt.new(self.^name ~ '|' ~ $abspath);
$lock.protect: {
%instances{$WHICH} //= self.bless(:$abspath, :$prefix, :$WHICH, |%_)
}
}

multi method Str(CompUnit::Repository::Locally:D:) { $!prefix.absolute }
multi method Str(CompUnit::Repository::Locally:D:) { $!abspath }
multi method gist(CompUnit::Repository::Locally:D:) {
self.path-spec
}
multi method perl(CompUnit::Repository::Locally:D:) {
$?CLASS.perl ~ '.new(prefix => ' ~ $!prefix.absolute.perl ~ ')';
$?CLASS.^name ~ '.new(prefix => ' ~ $!abspath.perl ~ ')';
}

multi method WHICH(CompUnit::Repository::Locally:D:) { $!WHICH }

method path-spec(CompUnit::Repository::Locally:D:) {
self.short-id ~ '#' ~ $!prefix.absolute;
self.short-id ~ '#' ~ $!abspath
}

method source-file(Str $name --> IO::Path:D) {
self.prefix.add($name)
}

method prefix { "{$!prefix}".IO }

method id() {
nqp::sha1(
self.next-repo
@@ -42,7 +50,7 @@ role CompUnit::Repository::Locally {
}

# stubs
method short-id(CompUnit::Repository::Locally:D:) {...}
method short-id(CompUnit::Repository::Locally:D:) { ... }
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit e9bbefd

Please sign in to comment.
You can’t perform that action at this time.