From f83c58d902c91c5e89f5cc1fa39b1d37f969f922 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 9 Nov 2016 17:53:34 -0800 Subject: [PATCH] Project.pm: support orphan project creation An orphan project is a project that is at least two levels deep but for which there exists no parent project that it's been forked from. The code already supports this complete with creation of any missing parent directories if not for some overzealous checking in valid_name. Therefore add some additional optional options to valid_name and the ghost functions to a) actually allow orphan project creation to proceed and b) to allow it to proceed even if subdirectories need to be created. Signed-off-by: Kyle J. McKay --- Girocco/Project.pm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index a855114..582aba8 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -551,8 +551,8 @@ sub _hooks_install { # private constructor, do not use sub _new { my $class = shift; - my ($name, $base_path, $path) = @_; - does_exist($name,1) || valid_name($name) or die "refusing to create project with invalid name ($name)!"; + my ($name, $base_path, $path, $orphan, $optp) = @_; + does_exist($name,1) || valid_name($name, $orphan, $optp) or die "refusing to create project with invalid name ($name)!"; $path ||= "$base_path/$name.git"; my $proj = { name => $name, base_path => $base_path, path => $path }; @@ -564,8 +564,8 @@ sub _new { # you can conjure() it later to disk sub ghost { my $class = shift; - my ($name, $mirror) = @_; - my $self = $class->_new($name, $Girocco::Config::reporoot); + my ($name, $mirror, $orphan, $optp) = @_; + my $self = $class->_new($name, $Girocco::Config::reporoot, undef, $orphan, $optp); $self->{users} = []; $self->{mirror} = $mirror; $self->{email} = $self->{orig_email} = ''; @@ -1346,12 +1346,16 @@ sub _valid_name_characters { and !has_reserved_suffix($_, $_[1], $_[2]); } +# $_[0] => prospective project name (WITHOUT trailing .git) +# $_[1] => true to allow orphans (i.e. two-or-more-level-deep projects without a parent) +# (the directory in which the orphan will be created must, however, already exist) +# $_[2] => true to allow orphans w/o needed directory if $_[1] also true (like mkdir -p) sub valid_name { no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning local $_ = $_[0]; _valid_name_characters($_) and not exists($reservedprojectnames{lc($_)}) and @{[m#/#g]} <= 5 # maximum fork depth is 5 - and ((not m#/#) or -d get_forkee_path($_)) # will also catch ^/ + and ((not m#/#) or -d get_forkee_path($_) or ($_[1] and ($_[2] or -d $Girocco::Config::reporoot.'/'.get_forkee_name($_)))) and (! -f $Girocco::Config::reporoot."/$_.git"); } -- 2.11.4.GIT