Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix double-open/close issues.
  • Loading branch information
jnthn committed Sep 25, 2013
1 parent d50a0fc commit 6336d4d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/core/IO.pm
Expand Up @@ -113,7 +113,8 @@ my class IO::Handle does IO::FileTestable {

method close() {
# TODO:b catch errors
nqp::closefh($!PIO);
nqp::closefh($!PIO) if nqp::istrue($!PIO);
$!PIO := Mu;
Bool::True;
}

Expand Down Expand Up @@ -255,8 +256,12 @@ my class IO::Handle does IO::FileTestable {
fail("File '" ~ self.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && self.e;

my $mode = $append ?? :a !! :w;
self.open(:$enc, |$mode);
if self.opened {
self.encoding($enc);
} else {
my $mode = $append ?? :a !! :w;
self.open(:$enc, |$mode);
}
self.print($contents);
self.close;
}
Expand All @@ -267,8 +272,10 @@ my class IO::Handle does IO::FileTestable {
fail("File '" ~ self.path ~ "' already exists, but :createonly was give to spurt")
if $createonly && self.e;

my $mode = $append ?? :a !! :w;
self.open(:bin, |$mode);
unless self.opened {
my $mode = $append ?? :a !! :w;
self.open(:bin, |$mode);
}
self.write($contents);
self.close;
}
Expand Down

0 comments on commit 6336d4d

Please sign in to comment.