From 6ac9ad55e06301b332bc506f6d7faff4a4d433cd Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Wed, 7 Aug 2013 09:56:10 -0700 Subject: [PATCH] Project.pm: slightly relax does_exist check In the case where forks have been kept but the forkee itself has actually been removed, the valid_name check will fail since it requires the forkee to still exist. Unfortunately this also causes the does_exist check to fail on these forks even though they actually do exist (and load will succeed). Relax the does_exist check so that if the forkee does not exist it's enough that the fork directory does exist before actually checking for the existence of the project itself. --- Girocco/Project.pm | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index bff001b..ce926f1 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -746,19 +746,34 @@ sub get_forkee_path { -d $forkee ? $forkee : ''; } -sub valid_name { - no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning +sub _valid_name_characters { local $_ = $_[0]; - (not m#/# or -d get_forkee_path($_)) # will also catch ^/ + (not m#^/#) + and (not m#//#) and (not m#\./#) and (not m#/$#) and m#^[a-zA-Z0-9+./_-]+$#; } +sub valid_name { + no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning + local $_ = $_[0]; + _valid_name_characters($_) + and ((not m#/#) or -d get_forkee_path($_)); # will also catch ^/ +} + +# It's possible that some forks have been kept but the forkee is gone. +# In this case the standard valid_name check is too strict. sub does_exist { no warnings; # avoid silly 'unsuccessful stat on filename with \n' warning - my ($name) = @_; - valid_name($name) or die "tried to query for project with invalid name $name!"; + my ($name, $nodie) = @_; + my $okay = ( + _valid_name_characters($name) + and ((not $name =~ m#/#) + or -d get_forkee_path($name) + or -d $Girocco::Config::reporoot.'/'.get_forkee_name($name))); + (!$okay && $nodie) and return undef; + !$okay and die "tried to query for project with invalid name $name!"; (-d $Girocco::Config::reporoot."/$name.git"); } -- 2.11.4.GIT