From: Matt S Trout Date: Fri, 22 May 2009 11:14:45 +0000 (+0100) Subject: correct symlink generation X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b5b2a791af5afe7cc43deeb33a43530121cf0024;p=engit%2FIron-Munger.git correct symlink generation --- diff --git a/lib/IronMunger/StatsSaver.pm b/lib/IronMunger/StatsSaver.pm index 3fd1e5b..304539f 100644 --- a/lib/IronMunger/StatsSaver.pm +++ b/lib/IronMunger/StatsSaver.pm @@ -26,7 +26,7 @@ class IronMunger::StatsSaver { $self->_image_symlink_from($user, $type), $self->_image_symlink_target($type, $level), ); - my $dir = File::Spec->catpath((File::Spec->splitpath($target))[0,1]); + my $dir = File::Spec->catpath((File::Spec->splitpath($from))[0,1]); mkpath($dir); symlink($target, $from) or confess "Couldn't symlink ${from} to ${target}: $!"; @@ -35,7 +35,11 @@ class IronMunger::StatsSaver { method _write_symlinks_for (IronMunger::Monger $monger) { foreach my $type (@types) { - foreach my $name (map $monger->$_, qw(name nick)) { + foreach my $name ( + map $monger->$_, + grep $monger->${\"has_$_"}, + qw(name nick) + ) { $self->_write_image_symlink($name, $type, $monger->level); } } diff --git a/t/stats_saver.t b/t/stats_saver.t index 4ffddd1..1bae8ad 100644 --- a/t/stats_saver.t +++ b/t/stats_saver.t @@ -2,7 +2,16 @@ use strict; use warnings; use Test::More qw(no_plan); use IO::All; -use File::Temp qw(tempdir); +use File::Temp (); + +sub tempdir { + if ($ENV{UNCLEAN_TEMP}) { + my $dir = File::Temp::tempdir; + warn $dir; + return $dir; + } + return File::Temp::tempdir(CLEANUP => 1); +} BEGIN { use_ok aliased => 'IronMunger::StatsSaver'; } BEGIN { use_ok aliased => 'IronMunger::Monger'; } @@ -29,12 +38,31 @@ my $monger = Monger->new( is($monger->level, 'paper', 'mst sucks'); -my $dir = tempdir(CLEANUP => 1); +my $dir = tempdir; $saver = StatsSaver->new(dir => $dir); $saver->_write_symlinks_for($monger); -my @links = sort map $_->readlink, grep -l, io($dir)->all_files; +my $bdir = io("${dir}/badges"); + +my $mbdir = io("${dir}/mybadge"); + +my %found_links; +do { + my @l = $mbdir->all_links(2); + @found_links{@l} = (1) x scalar @l; +}; + +foreach my $gender (qw(male female)) { + my $desc = "${gender} symlink"; + my $l = io("${mbdir}/${gender}/mst.png"); + ok($l->is_link, "${desc} exists"); + is( + $l->readlink, "${bdir}/${gender}/paper.png", + "${desc} points to right target", + ); + ok(delete $found_links{$l}, "${desc} in link list"); +} -warn join("\n", @links); +ok(!(keys %found_links), 'all links accounted for');