Skip to content

Commit

Permalink
fixed custom temporary directory bug in Mojo::Asset::File
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 6, 2013
1 parent c659eb9 commit eff7e8d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
Expand Up @@ -4,6 +4,7 @@
- Improved documentation.
- Improved tests.
- Fixed memory leak in development not found page.
- Fixed custom temporary directory bug in Mojo::Asset::File.

3.84 2013-01-30
- Deprecated after_static_dispatch hook in favor of before_routes.
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Asset/File.pm
Expand Up @@ -22,7 +22,7 @@ has handle => sub {
}

# Open new or temporary file
my $base = catfile File::Spec::Functions::tmpdir, 'mojo.tmp';
my $base = catfile $self->tmpdir, 'mojo.tmp';
my $name = $path // $base;
until ($handle->open($name, O_CREAT | O_EXCL | O_RDWR)) {
croak qq{Can't open file "$name": $!} if defined $path || $! != $!{EEXIST};
Expand Down
12 changes: 10 additions & 2 deletions t/mojo/asset.t
@@ -1,6 +1,9 @@
use Mojo::Base -strict;

use Test::More;
use File::Basename 'dirname';
use File::Path 'mkpath';
use File::Spec::Functions qw(catdir tmpdir);
use Mojo::Asset::File;
use Mojo::Asset::Memory;

Expand Down Expand Up @@ -168,8 +171,13 @@ ok !$asset->is_file, 'stored in memory';

# Temporary directory
{
local $ENV{MOJO_TMPDIR} = '/does/not/exist';
is(Mojo::Asset::File->new->tmpdir, '/does/not/exist', 'right value');
mkpath my $tmpdir = catdir tmpdir, 'test';
local $ENV{MOJO_TMPDIR} = $tmpdir;
$file = Mojo::Asset::File->new;
is($file->tmpdir, $tmpdir, 'same directory');
$file->add_chunk('works!');
is $file->slurp, 'works!', 'right content';
is dirname($file->path), $tmpdir, 'same directory';
}

# Temporary file without cleanup
Expand Down

0 comments on commit eff7e8d

Please sign in to comment.