Subject: | Error creating cache file if File::HomeDir->my_dist_data() returns undef. |
BUILD uses File::HomeDir->my_dist_data() when creating the path
attribute if it isn't specified, but doesn't check that its return
value is defined.
This leads to an error later in _transform_and_cache when it tries to
create the cache file.
It's possible for File::HomeDir->my_dist_data() to return undef. It
uses File::HomeDir->my_data(), and if that doesn't exist it won't be
created (regardless of the create flag to my_dist_data()).
This is possible on OS X if
$HOME/Library/Application\ Support/
doesn't exist. I.e.
% perl -w -MFile::HomeDir -E 'say File::HomeDir->my_data'
Use of uninitialized value in say at -e line 1.
In BUILD:
$self->path( catfile(File::HomeDir->my_dist_data( $DISTNAME, { create => 1 } ), $cache_file_name) );
passes that undef value to catfile, which is happy to accept an undef value, e.g.
% perl -MFile::Spec::Functions=catfile -E 'say catfile( undef, "foo" )'
/foo
This leads to the path being rooted at / instead of the user's disk space, which causes the following
line in _transform_and_cache
open(my $fh, '>', $self->path);
to fail, leading to an error that looks like this:
% perl -Mblib t/05-local.t
Can't open '/file%3A%2F%2F%2Fdata%2Fpelf1%2Fdj%2Fhd0%2Froot%2Fdot%2Fcpanm%2Fwork%2F1457483443.65487%2FPAUSE-Packages-0.17%2Ft%2F02packages.details.txt' for writing: 'Permission denied' at PAUSE-Packages-0.17/blib/lib/PAUSE/Packages.pm line 195
I'm not sure how to handle the undef return from my_dist_data, but
it'd be nicer if the error was caught earlier in PAUSE::Packages with
a clearer message.
Thanks,
Diab