kentnl / File-ShareDir-ProjectDistDir

Simple set-and-forget using of a '/share' directory in your projects root
Other
5 stars 5 forks source link

infinite loop in _devel_sharedir #2

Closed tantalor closed 12 years ago

tantalor commented 12 years ago

(using File::ShareDir::ProjectDistDir 0.3.1 and perl 5.12)

When I run this command from my shell, perl seems to enter a tight loop and consume 100% of CPU,

$ perl -MFile::ShareDir::ProjectDistDir -e 1

I dug into the source and found the loop in _devel_sharedir,

  while ( $dir->dir_list() and $dir->dir_list(-1) ne 'lib' ) {
    $dir = $dir->parent;
  }

The carp traceback,

    File::ShareDir::ProjectDistDir::_devel_sharedir('-e', 'share') called at /Library/Perl/5.12/File/ShareDir/ProjectDistDir.pm line 116
    File::ShareDir::ProjectDistDir::build_dist_dir('File::ShareDir::ProjectDistDir', 'dist_dir', 'HASH(0x7fb7ba833f38)', 'HASH(0x7fb7ba9085e8)') called at /System/Library/Perl/Extras/5.12/Sub/Exporter.pm line 856
    Sub::Exporter::default_generator('HASH(0x7fb7ba833f50)') called at /System/Library/Perl/Extras/5.12/Sub/Exporter.pm line 786
    Sub::Exporter::_do_import('HASH(0x7fb7ba837868)', 'ARRAY(0x7fb7ba940668)') called at /System/Library/Perl/Extras/5.12/Sub/Exporter.pm line 745
    Sub::Exporter::__ANON__(undef, ':all', 'defaults', 'HASH(0x7fb7ba82e278)') called at -e line 0
    main::BEGIN() called at /Library/Perl/5.12/File/ShareDir/ProjectDistDir.pm line 0
    eval {...} called at /Library/Perl/5.12/File/ShareDir/ProjectDistDir.pm line 0

I'm guessing the issue is that the / dir has a non-empty dir_list on my system,

use Path::Class::File;
use Data::Dumper;
my $file     = Path::Class::File->new('/');
my $dir      = $file->dir->absolute;
my @dir_list = $dir->dir_list();
print Dumper(\@dir_list);

$VAR1 = [
          '',
          ''
        ];

Is this not correct?

kentfredric commented 12 years ago

Sorry for the delay. Thanks for the bug report!

Just thinking, which seems to make more sense to you, stopping ascending when we detect "/" , ( which I have no idea if that is cross-platform reliable ) or stopping when seeing the same path twice? I should probably consult the masters of all things platform sensitive on IRC

kentfredric commented 12 years ago

Should be resolved in 0.3.2 : https://metacpan.org/diff/release/KENTNL/File-ShareDir-ProjectDistDir-0.3.1/KENTNL/File-ShareDir-ProjectDistDir-0.3.2

Thanks again for the bug report =). Sorry for the slight delay.

tantalor commented 12 years ago

Great, thanks for the fast fix.