From 9e89415138296e0e0bb54247bd8d6f446a604457 Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Wed, 17 Mar 2010 23:11:50 -0700 Subject: Handle changing owner. --- usr/src/libpiny/Piny/Repo.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'usr') diff --git a/usr/src/libpiny/Piny/Repo.pm b/usr/src/libpiny/Piny/Repo.pm index b10651f..5249b61 100644 --- a/usr/src/libpiny/Piny/Repo.pm +++ b/usr/src/libpiny/Piny/Repo.pm @@ -2,6 +2,8 @@ package Piny::Repo; use Moose; +use File::Find qw( find ); + use Piny::User; # Attributes @@ -36,8 +38,9 @@ has 'repostat' => ); has 'owner' => - ( is => 'ro' + ( is => 'rw' , isa => 'Piny::User' + , trigger => \&_change_owner , lazy_build => 1 , init_arg => undef ); @@ -81,6 +84,14 @@ sub _set_description { close( $fd ) or die "Error when closing " . $s->path( ) . "/description: $!"; }; +sub _change_owner { + my ( $s, $new_owner, $old_owner ) = @_; + + return unless defined $old_owner; + + find( { wanted => sub { chown( $new_owner->uid( ), -1, $_ ) or die "Couldn't chown $_: $!"; }, no_chdir => 1 }, $s->path( ) ); +}; + # Builder methods # If constructed with just one argument, then treat it as a repo name. -- cgit v1.2.3