Skip to content

Commit

Permalink
Merge pull request miyagawa#264 from ilmari/symlink-build-log
Browse files Browse the repository at this point in the history
Write build.log to work directory instead of home
  • Loading branch information
miyagawa committed Jun 5, 2013
2 parents 46ec86d + 034d2e7 commit 713c2e4
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions lib/App/cpanminus/script.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use aliased 'App::cpanminus::Dependency';

use constant WIN32 => $^O eq 'MSWin32';
use constant SUNOS => $^O eq 'solaris';
use constant CAN_SYMLINK => eval { symlink("", ""); 1 };

our $VERSION = $App::cpanminus::VERSION;

Expand Down Expand Up @@ -362,21 +363,30 @@ sub setup_home {
$self->{base} = "$self->{home}/work/" . time . ".$$";
File::Path::mkpath([ $self->{base} ], 0, 0777);

my $link = "$self->{home}/latest-build";
eval { unlink $link; symlink $self->{base}, $link };
# native path because we use shell redirect
$self->{log} = File::Spec->catfile($self->{base}, "build.log");
my $final_log = "$self->{home}/build.log";

$self->{log} = File::Spec->catfile($self->{home}, "build.log"); # because we use shell redirect
{ open my $out, ">$self->{log}" or die "$self->{log}: $!" }

{
my $log = $self->{log}; my $base = $self->{base};
if (CAN_SYMLINK) {
my $build_link = "$self->{home}/latest-build";
unlink $build_link;
symlink $self->{base}, $build_link;

unlink $final_log;
symlink $self->{log}, $final_log;
} else {
my $log = $self->{log}; my $home = $self->{home};
$self->{at_exit} = sub {
my $self = shift;
File::Copy::copy($self->{log}, "$self->{base}/build.log");
};
my $temp_log = "$home/build.log." . time . ".$$";
File::Copy::copy($log, $temp_log)
&& unlink($final_log)
&& rename($temp_log, $final_log);
}
}

{ open my $out, ">$self->{log}" or die "$self->{log}: $!" }

$self->chat("cpanm (App::cpanminus) $VERSION on perl $] built for $Config{archname}\n" .
"Work directory is $self->{base}\n");
}
Expand Down

0 comments on commit 713c2e4

Please sign in to comment.