| 1 | package VCI::VCS::Svn::Repository; | ||
| 2 | use Moose; | ||
| 3 | |||
| 4 | use Cwd qw (abs_path); | ||
| 5 | use SVN::Ra; | ||
| 6 | |||
| 7 | use VCI::Util qw(detaint); | ||
| 8 | |||
| 9 | extends 'VCI::Abstract::Repository'; | ||
| 10 | |||
| 11 | has 'x_ra' => (is => 'ro', isa => 'SVN::Ra', lazy => 1, | ||
| 12 | default => sub { SVN::Ra->new(url => shift->x_root_noslash) }); | ||
| 13 | |||
| 14 | # The SVN libraries throw an error in certain cases if the root ends with | ||
| 15 | # a slash. | ||
| 16 | has 'x_root_noslash' => (is => 'ro', isa => 'Str', lazy => 1, | ||
| 17 | default => sub { my $root = shift->root; $root =~ s|/+\s*$||; $root }); | ||
| 18 | |||
| 19 | sub BUILD { | ||
| 20 | my $self = shift; | ||
| 21 | # Make relative local roots into absolute roots. | ||
| 22 | my $root = $self->root; | ||
| 23 | if ($root =~ m|^file://|) { | ||
| 24 | $root =~ m|^file://(localhost/)?(.*)$|; | ||
| 25 | my $dir = abs_path($2); | ||
| 26 | # Because of Abstract::Repository::BUILD, we know that $root is not | ||
| 27 | # tainted. Thus turning it into an absolute path should be safe. | ||
| 28 | # Theoretically there could be dangerous things in the absolute | ||
| 29 | # path that aren't in the relative path, but we only use this root | ||
| 30 | # via the SVN API, so we should be safe. | ||
| 31 | detaint($dir); | ||
| 32 | $self->{root} = "file://$dir"; | ||
| 33 | } | ||
| 34 | $self->_root_always_ends_with_slash; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub _build_projects { | ||
| 38 | my $self = shift; | ||
| 39 | my $contents = $self->root_project->root_directory->contents; | ||
| 40 | my @projects; | ||
| 41 | foreach my $item (@$contents) { | ||
| 42 | next if !$item->isa('VCI::VCS::Svn::Directory'); | ||
| 43 | my $project = $self->project_class->new( | ||
| 44 | name => $item->name, repository => $self, | ||
| 45 | root_directory => $item); | ||
| 46 | push(@projects, $project); | ||
| 47 | } | ||
| 48 | |||
| 49 | return \@projects; | ||
| 50 | } | ||
| 51 | |||
| 52 | sub _build_root_project { $_[0]->_root_project; } | ||
| 53 | |||
| 54 | __PACKAGE__->meta->make_immutable; | ||
| 55 | |||
| 56 | 1; |