Skip to content

Commit

Permalink
fix #7: File::Find follows symlinks and Cwd's realpath resolves symli…
Browse files Browse the repository at this point in the history
…nks. Now File::Spec->rel2abs is used instead.
  • Loading branch information
reneeb committed Jan 26, 2018
1 parent 1e136f6 commit f582165
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -5,6 +5,7 @@ MANIFEST
t/00_load.t
t/01_selftest.t
t/xt/02_issue1.t
t/xt/03_issue7.t
't/file with whitespaces.txt'
t/testrules.yml

Expand Down
12 changes: 7 additions & 5 deletions lib/Test/CheckManifest.pm
Expand Up @@ -12,7 +12,7 @@ use File::Basename;
use Test::Builder;
use File::Find;

our $VERSION = '1.31';
our $VERSION = '1.32';
our $VERBOSE = 1;

my $test = Test::Builder->new();
Expand Down Expand Up @@ -130,14 +130,16 @@ sub ok_manifest{
for my $tfile(@files){
$tfile = (split(/\s{2,}/,$tfile,2))[0];
next unless -e $home . '/' . $tfile;
$tfile = Cwd::realpath($home . '/' . $tfile);
$tfile = File::Spec->rel2abs($home . '/' . $tfile);
}

my (@dir_files,%files_hash,%excluded);
@files_hash{@files} = ();

find({no_chdir => 1,
wanted => sub{
find({
no_chdir => 1,
follow => 0,
wanted => sub {
my $file = $File::Find::name;
my $is_excluded = _is_excluded(
$file,
Expand All @@ -148,7 +150,7 @@ sub ok_manifest{
$home,
);

push(@dir_files,Cwd::realpath($file)) if -f $file and !$is_excluded;
push(@dir_files,File::Spec->rel2abs($file)) if -f $file and !$is_excluded;

$excluded{$file} = 1 if -f $file and $is_excluded
}
Expand Down
34 changes: 34 additions & 0 deletions t/xt/03_issue7.t
@@ -0,0 +1,34 @@
#!/usr/bin/perl

use strict;
use warnings;

use Test::More;
use Test::CheckManifest;
use IO::File;
use File::Basename;
use File::Spec;

SKIP: {
skip 'Test not needed on Windows', 1 if $^O =~ /Win32/;

{
my $dir = dirname( File::Spec->rel2abs( __FILE__ ) );

# create file
my $fh_manifest = IO::File->new( $dir . '/MANIFEST', 'w' );
$fh_manifest->print( $_ . "\n" ) for (qw/MANIFEST A.txt B.txt 02_issue1.t 03_issue7.t/);
$fh_manifest->close or die $!;

# create file
my $fh = IO::File->new( $dir . '/A.txt', 'w' );
$fh->print( scalar localtime ) or die $!;
$fh->close or die $!;

# create symlink
eval { symlink $dir . '/A.txt', $dir . '/B.txt' };

ok_manifest({ dir => $dir });
}

}

0 comments on commit f582165

Please sign in to comment.