From 5e4e9675d39413c22568100372bc82f07495a700 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Tue, 29 Jun 2010 22:38:57 -0700 Subject: First run at lsaccess and lsrepo. --- usr/src/libpiny/lib/Piny/Repo.pm | 22 ++++++++++++++++++++++ usr/src/libpiny/lib/Piny/User.pm | 26 ++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) (limited to 'usr/src/libpiny/lib') diff --git a/usr/src/libpiny/lib/Piny/Repo.pm b/usr/src/libpiny/lib/Piny/Repo.pm index 6dcabca..26d936a 100644 --- a/usr/src/libpiny/lib/Piny/Repo.pm +++ b/usr/src/libpiny/lib/Piny/Repo.pm @@ -99,6 +99,12 @@ sub remove_access { $s->group( )->remove_member( @users ); }; +sub has_access { + my ( $s, $user ) = @_; + + return $s->owner( )->uid( ) == $user->uid( ) or $user->has_group( $s->group( ) ); +}; + # Triggers sub _rename_repo { @@ -132,6 +138,22 @@ sub _change_owner { find( { wanted => sub { chown( $new_owner->uid( ), -1, $_ ) or die "Couldn't chown $_: $!"; }, no_chdir => 1 }, $s->path( ) ); }; +# Class methods + +sub all_repos { + my ( $class, $dir ) = @_; + + $dir = "/srv/git" unless defined $dir; + + my @ret; + + find( { wanted => sub { print "$_\n"; if ( /^[^.].*\.git$/ ) { $File::Find::prune = 1; push( @ret, $File::Find::name ); }; } }, $dir ); + + @ret = map { print "$_ "; s/^\Q$dir\E\/?//; s/\.git$//; print "$_\n"; $class->new( name => $_ ); } @ret; + + return @ret; +}; + # Builder methods # If constructed with just one argument, then treat it as a repo name. diff --git a/usr/src/libpiny/lib/Piny/User.pm b/usr/src/libpiny/lib/Piny/User.pm index e0687a3..f9a5f0d 100644 --- a/usr/src/libpiny/lib/Piny/User.pm +++ b/usr/src/libpiny/lib/Piny/User.pm @@ -77,6 +77,32 @@ sub remove_group { }; }; +sub has_group { + my ( $s, $group ) = @_; + + foreach my $owngroup ( $s->groups( ) ) { + return if $owngroup->gid( ) == $group->gid( ); + }; + + return; +}; + +# Class methods + +sub all_users { + my ( $class ) = @_; + + endpwent( ); + + my @ret; + + while ( my @info = getpwent( ) ) { + push( @ret, $class->new( uid => $info[2] ) ); + }; + + return @ret; +}; + # Builder methods # If constructed with just one argument, then -- cgit v1.2.3