From 0d3d61bad598c1b68ddf272e44d330bcbcb1cd74 Mon Sep 17 00:00:00 2001 From: Andrew Yates <ayates@ebi.ac.uk> Date: Thu, 14 Jun 2012 08:40:07 +0000 Subject: [PATCH] A more succient version of the method. --- modules/Bio/EnsEMBL/Pipeline/Base.pm | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/Bio/EnsEMBL/Pipeline/Base.pm b/modules/Bio/EnsEMBL/Pipeline/Base.pm index f1e0e6a193..4e1e8d0133 100644 --- a/modules/Bio/EnsEMBL/Pipeline/Base.pm +++ b/modules/Bio/EnsEMBL/Pipeline/Base.pm @@ -128,17 +128,19 @@ sub production_name { return $prod; } -# Closes file handle, and deletes the file stub if it contains no data -# Returns success type +# Closes file handle, and deletes the file stub if no data was written to +# the file handle (using tell). We can also only close a file handle and unlink +# the data if it was open otherwise we just ignore it +# Returns success if we managed to close/delete the file sub tidy_file_handle { my ($self, $fh, $path) = @_; - if ($fh->tell() == 0) { - $fh->close() if $fh->opened(); - unlink($path) if -f $path; + if($fh->opened()) { + my $unlink = ($fh->tell() == 0) ? 1 : 0; + $fh->close(); + unlink($path) if -f $path && $unlink; return 1; - } - $fh->close() if $fh->opened(); + } return 0; } -- GitLab