From: Michael Reddick Date: Tue, 22 May 2012 22:32:24 +0000 (-0500) Subject: create pidbase directory if it doesnt exist X-Git-Tag: 0.15~4^2~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e803cff500bb7c9926ef94e9ef5a973d8fd103b6;p=gitmo%2FMooseX-Daemonize.git create pidbase directory if it doesnt exist --- diff --git a/lib/MooseX/Daemonize.pm b/lib/MooseX/Daemonize.pm index 5c627ba..7a8c3c6 100644 --- a/lib/MooseX/Daemonize.pm +++ b/lib/MooseX/Daemonize.pm @@ -2,6 +2,7 @@ package MooseX::Daemonize; use strict; # because Kwalitee is pedantic use Moose::Role; use MooseX::Types::Path::Class; +use File::Path qw(make_path); our $VERSION = '0.13'; @@ -81,6 +82,15 @@ has exit_code => ( sub init_pidfile { my $self = shift; my $file = $self->pidbase . '/' . $self->progname . '.pid'; + + if ( !-d $self->pidbase ) { + make_path( $self->pidbase, { error => \my $err } ); + if (@$err) { + confess sprintf( "Cannot create pidbase directory '%s': %s", + $self->pidbase, @$err ); + } + } + confess "Cannot write to $file" unless (-e $file ? -w $file : -w $self->pidbase); MooseX::Daemonize::Pid::File->new( file => $file ); } diff --git a/t/01.filecreate.t b/t/01.filecreate.t index b0af491..4319d0d 100644 --- a/t/01.filecreate.t +++ b/t/01.filecreate.t @@ -45,7 +45,7 @@ $ENV{MX_DAEMON_STDERR} = catfile($dir, 'Err.txt'); } my $app = FileMaker->new( - pidbase => $dir, + pidbase => "$dir/subdir", filename => $FILENAME, ); isa_ok($app, 'FileMaker'); @@ -55,7 +55,7 @@ does_ok($app, 'MooseX::Daemonize::Core'); isa_ok($app->pidfile, 'MooseX::Daemonize::Pid::File'); -is($app->pidfile->file, catfile($dir, "filemaker.pid"), '... got the right PID file path'); +is($app->pidfile->file, catfile("$dir/subdir", "filemaker.pid"), '... got the right PID file path'); ok(not(-e $app->pidfile->file), '... our pidfile does not exist'); ok(!$app->status, '... the daemon is running');