Skip to content

Commit

Permalink
Fix path ascension bug
Browse files Browse the repository at this point in the history
  • Loading branch information
kentfredric committed May 7, 2012
1 parent 1392cc3 commit e18446e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
16 changes: 16 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
Release history for File-ShareDir-ProjectDistDir

{{$NEXT}}
[Bugs]
- github#2 There was a bug on some platforms where
Path::Class::Dir->new('/')->parent->dir_list() returned a 2-item list
instead of a one-item list which was our loop termination criteria. This
became an infinite death loop on all platforms that have a "volume" (
mac, win ). Has been resolved by performing a check to see if the path
is the OS Specific path that represents a "root" from
File::Spec->rootdir. Feedback on if this works or not requested, and if
this still is a problem, I'll use $dir->parent eq $dir being the loop
terminator.

[Dependencies::Changed]
- develop recommends : Dist::Zilla::PluginBundle::Author::KENTNL::Lite
0.01009803 -> v1.3.0
- develop suggests : Dist::Zilla::PluginBundle::Author::KENTNL
v1.2.0 -> v1.3.0

0.3.1 2012-03-07T03:57:06Z
[00 Summary]
Expand Down
25 changes: 18 additions & 7 deletions lib/File/ShareDir/ProjectDistDir.pm
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Import the dist_file method
->import( .... , projectdir => 'share' )
Specify what the "project dir" is as a path relative to the base of your distributions source,
Specify what the "project dir" is as a path relative to the base of your distributions source,
and this directory will be used as a ShareDir simulation path for the exported methods I<During development>.
If not specified, the default value 'share' is used.
Expand All @@ -87,7 +87,7 @@ If not specified, the default value 'share' is used.
->import( .... , filename => 'some/path/to/foo.pm' );
Generally you don't want to set this, as its worked out by caller() to work out the name of
Generally you don't want to set this, as its worked out by caller() to work out the name of
the file its being called from. This file's path is walked up to find the 'lib' element with a sibling
of the name of your 'projectdir'.
Expand All @@ -96,7 +96,7 @@ of the name of your 'projectdir'.
->import( .... , distname => 'somedistname' );
Specifying this argument changes the way the functions are emitted at I<installed runtime>, so that instead of
taking the standard arguments File::ShareDir does, the specification of the distname in those functions is eliminated.
taking the standard arguments File::ShareDir does, the specification of the distname in those functions is eliminated.
ie:
Expand All @@ -119,7 +119,7 @@ ie:
projectdir => ....,
});
This is mostly an alternative syntax for specifying C<filename> and C<projectdir>,
This is mostly an alternative syntax for specifying C<filename> and C<projectdir>,
which is mostly used internally, and their corresponding other values are packed into this one.
=back
Expand All @@ -132,7 +132,7 @@ which is mostly used internally, and their corresponding other values are packed
sub import {
my ($caller_class, $caller_file, $caller_line ) = caller();
if ( grep { /share/ } @_ ) {
if ( grep { /share/ } @_ ) {
require File::ShareDir::ProjectDistDir;
File::ShareDir::ProjectDistDir->import(
filename => $caller_file,
Expand Down Expand Up @@ -212,9 +212,20 @@ sub _devel_sharedir {
my ( $filename, $subdir ) = @_;
my $file = Path::Class::File->new($filename);
my $dir = $file->dir->absolute;
my $root = File::Spec->rootdir();

## no critic ( ProhibitMagicNumbers )
while ( $dir->dir_list() and $dir->dir_list(-1) ne 'lib' ) {
$dir = $dir->parent;
while (1) {
if( $dir->dir_list(-1) eq 'lib' ) {
last;
}
if( File::Spec->catdir($dir->absolute->dir_list) eq $root ) {
#warn "Not a devel $dir, / hit";
return;
}
if( $dir->dir_list(-1) ne 'lib' ) {
$dir = $dir->parent;
}
}
if ( -d $dir->parent()->subdir($subdir) ) {
return $dir->parent()->subdir($subdir);
Expand Down

0 comments on commit e18446e

Please sign in to comment.