Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Better unlinking of temp files/directories
Using the default behavior of File::Temp means the files are unlinked when the filehandle is garbage collected, which can cause problems if it happens at random times. Instead do it manually in a LEAVE block.
  • Loading branch information
MasterDuke17 committed Aug 22, 2016
1 parent 540aba6 commit 4a65abd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 40 deletions.
11 changes: 7 additions & 4 deletions Benchable.p6
Expand Up @@ -73,6 +73,7 @@ multi method irc-to-me($message where .text ~~ /^ \s* $<config>=([:i compare \s]

method process($message, $config, $code is copy) {
my $start-time = now;
my $old-dir = $*CWD;

my $msg-response = '';
my %graph;
Expand All @@ -81,9 +82,7 @@ method process($message, $config, $code is copy) {
if $config ~~ / ',' / {
@commits = $config.split: ',';
} elsif $config ~~ /^ $<start>=\S+ \.\. $<end>=\S+ $/ {
my $old-dir = $*CWD;
chdir RAKUDO;
LEAVE chdir $old-dir;
return "Bad start" if run('git', 'rev-parse', '--verify', $<start>).exitcode != 0;
return "Bad end" if run('git', 'rev-parse', '--verify', $<end>).exitcode != 0;

Expand Down Expand Up @@ -134,9 +133,7 @@ method process($message, $config, $code is copy) {
# recursively find the commit in the middle until there are either no more large speed differences or no
# more commits inbetween (i.e., the next commit is the exact one that caused the difference)
if $config ~~ /:i releases / or $config ~~ / ',' / {
my $old-dir = $*CWD;
chdir RAKUDO;
LEAVE chdir $old-dir;

Z: loop (my int $x = 0; $x < +@commits - 1; $x++) {
if (now - $start-time > TOTAL-TIME) {
Expand All @@ -162,6 +159,7 @@ Z: loop (my int $x = 0; $x < +@commits - 1; $x++) {
}

if @commits >= ITERATIONS {
chdir $old-dir;
my $gfilename = 'graph.svg';
my $title = "$config $code".trans(['"'] => ['\"']);
my @ydata = @commits.map({ .<err> // .<min> with %times{$_.substr(0, 7)} });
Expand Down Expand Up @@ -194,6 +192,11 @@ Z: loop (my int $x = 0; $x < +@commits - 1; $x++) {
$msg-response ~= '¦' ~ @commits.map({ my $c = .substr(0, 7); "«$c»:" ~ (%times{$c}<err> // %times{$c}<min> // %times{$c}) }).join("\n¦");

return ($msg-response, %graph);

LEAVE {
chdir $old-dir;
unlink $filename;
}
}

Benchable.new.selfrun(benchable6, [bench]);
Expand Down
73 changes: 39 additions & 34 deletions Bisectable.p6
Expand Up @@ -20,6 +20,7 @@ use lib ‘.’;
use Whateverable;

use File::Temp;
use File::Directory::Tree;
use IRC::Client;

unit class Bisectable is Whateverable;
Expand Down Expand Up @@ -76,7 +77,7 @@ method test-commit($code-file, $compare-to?) {
my ($output, $exit-code) = self.get-output($perl6, '--setting=RESTRICTED', '--', $code-file);
$log ~= "»»»»» Script output:\n";
$log ~= $output;
$log ~= "»»»»» Script exit code: $exit-code\n";
$log ~= "\n»»»»» Script exit code: $exit-code\n";

# plain bisect
unless $compare-to {
Expand Down Expand Up @@ -104,11 +105,11 @@ method test-commit($code-file, $compare-to?) {
$log ~= "»»»»» Comparing the output to:\n";
$log ~= $output-good;
if $output eq $output-good {
$log ~= "»»»»» The output is identical\n";
$log ~= "\n»»»»» The output is identical\n";
$log ~= "»»»»» Final exit code: 0\n";
return ($log, 0);
} else {
$log ~= "»»»»» The output is different\n";
$log ~= "\n»»»»» The output is different\n";
$log ~= "»»»»» Final exit code: 1\n";
return ($log, 1);
}
Expand Down Expand Up @@ -187,49 +188,53 @@ method process($message, $code is copy, $good, $bad) {
my $output-file = ;
if $exit-good == $exit-bad {
$message.reply: Exit code is $exit-bad on both starting points (good=$short-good bad=$short-bad), bisecting by using the output;
($output-file, my $fh) = tempfile :unlink;
($output-file, my $fh) = tempfile :!unlink;
$fh.print: $out-good;
$fh.close;
}
if $exit-good != $exit-bad and $exit-good != 0 {
$message.reply: For the given starting points (good=$short-good bad=$short-bad), exit code on a ‘good’ revision is $exit-good (which is bad), bisecting with inverted logic;
}

my $result; # RT 128872
{
my $dir = tempdir :unlink;
run(git, clone, RAKUDO, $dir);
chdir $dir;
LEAVE chdir $old-dir;

self.get-output(git, bisect, start);
self.get-output(git, bisect, good, $full-good);
my ($init-output, $init-status) = self.get-output(git, bisect, bad, $full-bad);
if $init-status != 0 {
$message.reply: bisect log: ~ self.upload({ query => $message.text,
description => $message.server.current-nick,
result => $init-output });
return bisect init failure;
}
my ($bisect-output, $bisect-status);
if $output-file {
($bisect-output, $bisect-status) = self.run-bisect($filename, $output-file);
} else {
if $exit-good == 0 {
($bisect-output, $bisect-status) = self.run-bisect($filename);
} else {
($bisect-output, $bisect-status) = self.run-bisect($filename, $exit-good);
}
}
my $dir = tempdir :!unlink;
run(git, clone, RAKUDO, $dir);
chdir $dir;

self.get-output(git, bisect, start);
self.get-output(git, bisect, good, $full-good);
my ($init-output, $init-status) = self.get-output(git, bisect, bad, $full-bad);
if $init-status != 0 {
$message.reply: bisect log: ~ self.upload({ query => $message.text,
description => $message.server.current-nick,
result => $init-output\n$bisect-output });
result => $init-output });
return bisect init failure;
}
my ($bisect-output, $bisect-status);
if $output-file {
($bisect-output, $bisect-status) = self.run-bisect($filename, $output-file);
} else {
if $exit-good == 0 {
($bisect-output, $bisect-status) = self.run-bisect($filename);
} else {
($bisect-output, $bisect-status) = self.run-bisect($filename, $exit-good);
}
}
$message.reply: bisect log: ~ self.upload({ query => $message.text,
description => $message.server.current-nick,
result => $init-output\n$bisect-output });

return ‘bisect run’ failure if $bisect-status != 0;
if $bisect-status != 0 {
return ‘bisect run’ failure;
} else {
return self.get-output(git, show, --quiet, --date=short, --pretty=(%cd) {LINK}/%h, bisect/bad).first;
}

($result,) = self.get-output(git, show, --quiet, --date=short, --pretty=(%cd) {LINK}/%h, bisect/bad);
LEAVE {
chdir $old-dir;
unlink $output-file;
unlink $filename;
rmtree $dir;
}
return $result;
}

Bisectable.new.selfrun(bisectable6, [bisect]);
Expand Down
6 changes: 5 additions & 1 deletion Committable.p6
Expand Up @@ -47,7 +47,6 @@ method process($message, $config, $code is copy) {
{
my $old_dir = $*CWD;
chdir RAKUDO;
LEAVE chdir $old_dir;
return Bad start if run(git, rev-parse, --verify, $<start>).exitcode != 0;
return Bad end if run(git, rev-parse, --verify, $<end>).exitcode != 0;
($result, $exit-status, $exit-signal, $time) = self.get-output(git, rev-list, $<start>^..$<end>);
Expand Down Expand Up @@ -105,6 +104,11 @@ method process($message, $config, $code is copy) {

my $msg-response = ¦ ~ @result.map({ «{.<commits>.join(,)}»: {.<output>} }).join(\n¦);
return $msg-response;

LEAVE {
chdir $old_dir;
unlink $filename;
}
}

Committable.new.selfrun(committable6, [commit]);
Expand Down
2 changes: 1 addition & 1 deletion Whateverable.pm6
Expand Up @@ -114,7 +114,7 @@ method to-full-commit($commit) {
}

method write-code($code) {
my ($filename, $filehandle) = tempfile :unlink;
my ($filename, $filehandle) = tempfile :!unlink;
$filehandle.print: $code;
$filehandle.close;
return $filename
Expand Down

0 comments on commit 4a65abd

Please sign in to comment.