From: Vincent Pit Date: Fri, 5 Mar 2010 23:55:33 +0000 (+0100) Subject: Only apply abs_path() to paths that are either relative or that contains .. X-Git-Tag: v0.08~1 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=a2a9110d666dcd61af2573a7ad977cf441587d21;p=perl%2Fmodules%2Frgit.git Only apply abs_path() to paths that are either relative or that contains .. --- diff --git a/lib/App/Rgit/Config.pm b/lib/App/Rgit/Config.pm index 66548af..23874c5 100644 --- a/lib/App/Rgit/Config.pm +++ b/lib/App/Rgit/Config.pm @@ -4,11 +4,11 @@ use strict; use warnings; use Carp (); # confess -use Cwd (); # cwd, abs_path +use Cwd (); # cwd use File::Spec (); # canonpath, catfile, path use App::Rgit::Repository; -use App::Rgit::Utils qw/:levels/; +use App::Rgit::Utils qw/:levels/; # :levels, abs_path use constant IS_WIN32 => $^O eq 'MSWin32'; @@ -50,7 +50,7 @@ sub new { ? $ENV{GIT_DIR} : Cwd::cwd; Carp::confess("Invalid root directory") unless -d $root; - $root = File::Spec->canonpath(Cwd::abs_path($root)); + $root = File::Spec->canonpath(App::Rgit::Utils::abs_path($root)); my $git; my @candidates = ( @@ -74,7 +74,7 @@ sub new { } } Carp::confess("Couldn't find a proper git executable") unless defined $git; - $git = File::Spec->canonpath(Cwd::abs_path($git)); + $git = File::Spec->canonpath(App::Rgit::Utils::abs_path($git)); my $conf = 'App::Rgit::Config::Default'; eval "require $conf; 1" or Carp::confess("Couldn't load $conf: $@"); diff --git a/lib/App/Rgit/Repository.pm b/lib/App/Rgit/Repository.pm index ec08d4b..c340942 100644 --- a/lib/App/Rgit/Repository.pm +++ b/lib/App/Rgit/Repository.pm @@ -3,10 +3,12 @@ package App::Rgit::Repository; use strict; use warnings; -use Cwd (); # cwd, abs_path +use Cwd (); # cwd use File::Spec (); # canonpath, catdir, splitdir, abs2rel use POSIX (); # WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG SIGINT SIGQUIT +use App::Rgit::Utils (); # abs_path + my ($WIFEXITED, $WEXITSTATUS, $WIFSIGNALED, $WTERMSIG); BEGIN { @@ -55,7 +57,7 @@ sub new { my $dir = $args{dir}; if (defined $dir) { - $dir = Cwd::abs_path($dir); + $dir = App::Rgit::Utils::abs_path($dir); } else { $dir = Cwd::cwd; } diff --git a/lib/App/Rgit/Utils.pm b/lib/App/Rgit/Utils.pm index 75fe11e..21004de 100644 --- a/lib/App/Rgit/Utils.pm +++ b/lib/App/Rgit/Utils.pm @@ -3,6 +3,9 @@ package App::Rgit::Utils; use strict; use warnings; +use Cwd (); # abs_path +use File::Spec (); # file_name_is_absolute, updir, splitdir, splitpath + =head1 NAME App::Rgit::Utils - Miscellaneous utilities for App::Rgit classes. @@ -21,6 +24,29 @@ Miscellaneous utilities for L classes. This is an internal module to L. +=head1 FUNCTIONS + +=head2 C + +Forcefully make a path C<$path> absolute (in L's meaning of the term) when it isn't already absolute or when it contains C<'..'>. + +=cut + +sub abs_path { + my ($path) = @_; + + if (File::Spec->file_name_is_absolute($path)) { + my $updir = File::Spec->updir; + my @chunks = File::Spec->splitdir((File::Spec->splitpath($path))[1]); + + unless (grep $_ eq $updir, @chunks) { + return $path; + } + } + + return Cwd::abs_path($path); +} + =head1 CONSTANTS =head2 C, C, C, C @@ -51,6 +77,8 @@ use constant { =head1 EXPORT +L is only exported on request. + C C, C and C are only exported on request, either by their name or by the C<'codes'> tags. C, C, C and C are only exported on request, either by their name or by the C<'levels'> tags. @@ -61,6 +89,7 @@ use base qw/Exporter/; our @EXPORT = (); our %EXPORT_TAGS = ( + funcs => [ qw/abs_path/ ], codes => [ qw/SAVE NEXT REDO LAST/ ], levels => [ qw/INFO WARN ERR CRIT/ ], );