Commit 94464c19 authored by Karl Kornel's avatar Karl Kornel
Browse files

Move file creation to right before writing

Don't bother creating a file until we know there's something to write!
parent e0eb32ab
Loading
Loading
Loading
Loading
+16 −16
Original line number Diff line number Diff line
@@ -660,22 +660,6 @@ sub dolog {
sub drive_run {
    my ($command_path, $library_id, $output_path) = @_;

    # Open our output file
    # NOTE: We DO overwrite files here, so it's up to the caller to
    # ensure that the file is OK to override.
    my $output_file;
    open($output_file, '>', $output_path) or do {
        dolog(<<"EOF");
There was a problem opening the samplesheet file for writing!
The file we tried to write to: $output_path
The error we got: $!
EOF
        email_failure('Problem writing to samplesheet.csv', 'run',
                  $RUNFOLDER, "$RealBin/email-recipients.txt",
                  $LOGPATH, \$LOG, $RealBin, $RealScript);
        return undef;
    };

    # Work out our drive search command:
    # * Make the most recent item appear first on the list.
    # * Only return one item (so, we get the most recent).
@@ -762,6 +746,22 @@ EOF
    }
    dolog("Found file '${file_name}' with unique ID ${file_uid}!  Downloading...\n");

    # Open our output file
    # NOTE: We DO overwrite files here, so it's up to the caller to
    # ensure that the file is OK to override.
    my $output_file;
    open($output_file, '>', $output_path) or do {
        dolog(<<"EOF");
There was a problem opening the samplesheet file for writing!
The file we tried to write to: $output_path
The error we got: $!
EOF
        email_failure('Problem writing to samplesheet.csv', 'run',
                  $RUNFOLDER, "$RealBin/email-recipients.txt",
                  $LOGPATH, \$LOG, $RealBin, $RealScript);
        return undef;
    };

    # NOW we can finally get our file!
    @drive_options = (
        $command_path,