Skip to content

Commit

Permalink
Show directories in readdir:
Browse files Browse the repository at this point in the history
When `opendir()` is run, it creates an object for the directory using
the content of that directory. The `contents()` method did not include
directories in the listing.

Resolves GH cpanel#105.
  • Loading branch information
xsawyerx committed Jan 29, 2022
1 parent a3125ce commit 49ded54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Test/MockFile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ sub contents {
my $dirname = $self->path();
my @existing_files = sort map {
( my $basename = $_->path() ) =~ s{^\Q$dirname/\E}{}xms;
defined $_->{'contents'} || $_->is_link() ? ($basename) : ();
defined $_->{'contents'} || $_->is_link() || $_->is_dir() ? ($basename) : ();
} _files_in_dir($dirname);

return [ '.', '..', @existing_files ];
Expand Down
7 changes: 4 additions & 3 deletions t/opendir.t
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ is( $! + 0, ENOTDIR, '$! numeric is right.

# Check symlinks appear in readdir
my $dir_for_symlink = Test::MockFile->dir('/foo');
my $dir_in_dir = Test::MockFile->dir('/foo/infoo');
my $symlink_dest = Test::MockFile->file( '/foo/dest', '' );
my $symlink = Test::MockFile->symlink( '/foo/dest', '/foo/source' );

opendir my $sdh, '/foo' or die $!;
my @contents = readdir $sdh;
closedir $sdh or die $!;
is(
\@contents,
[ qw< . .. dest source > ],
'Symlink appears in directory content'
[ sort @contents ],
[ qw< . .. dest infoo source > ],
'Symlink and directories appears in directory content'
);

done_testing();
Expand Down

0 comments on commit 49ded54

Please sign in to comment.