Commit 8bab242b authored by Karl Kornel's avatar Karl Kornel
Browse files

Forgot to handle the buffer properly

parent 16c3991d
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -699,7 +699,8 @@ EOF
    # Actually spawn the search command.
    my $search_inhandle;
    my $results_handle = gensym();
    my $search_buffer = '';
    my $search_buffer;
    my $search_output = '';
    my $search_pid;
    eval {
        $search_pid = open3($search_inhandle, $results_handle, $results_handle,
@@ -717,20 +718,28 @@ EOF
    close($search_inhandle);

	# Pull output into the buffer, and then clean up.
	while (read($results_handle, $drive_buffer, 10)) {
        1;
	while (read($results_handle, $search_buffer, 10)) {
        $search_output .= $search_buffer;
	}
    dolog($search_buffer);
	waitpid($search_pid, 0);
	my $drive_search_exit_code = $? >> 8;
    dolog($search_output);
	close($results_handle);

    # Make sure we have something in the buffer
    if (!defined($search_output) or !$search_output) {
        dolog(<<"EOF");
Problem!
EOF
        return undef;
    }

    # Get the file UID with a fun compound split:
    # First, split the search buffer into multiple lines.
    # Grab the second line.
    # Next, split the retrieved line into space-separated fields.
    # The first field is our UID.
    my $file_uid = (split(/\s+/, (split(/\n/, $search_buffer))[1]))[0];
    my ($file_uid, $file_name) = (split(/\s+/, (split(/\n/, $search_output))[1]))[0,1];
    if (!defined($file_uid) or !$file_uid) {
        dolog(<<"EOF");
We could not find a matching sample sheet for this library ID.