# Buggy code
def _extractKeyInfoFromUrl(url):
    """
    :return: (bucket, key)
    """
    s3 = boto.connect_s3()
    bucket = s3.get_bucket(url.netloc)
    key = bucket.new_key(url.path[1:])
    return bucket, key


# Traceback (boto.exception.S3ResponseError)
2016-04-26 14:13:37,623 ERROR:root: Got exception 'S3ResponseError: 400 Bad Request
<Error><Code>InvalidRequest</Code><Message>The specified copy source is larger than the maximum allowable size for a copy source: 5368709120</Message><RequestId>CCB50A66B881B563</RequestId><HostId>1dAVKee/hXEaLCvisKyxUHlWtLbZwqcedEXOsKVSzAoE5ISrsuykzg9teW9vzidQaIqImJxbNgI=</HostId></Error>' while writing 's3://1000genomes/phase3/data/HG01977/sequence_read/SRR360135_1.filt.fastq.gz'
Traceback (most recent call last):
File "/usr/local/bin/cwltoil", line 9, in <module>
load_entry_point('toil==3.2.0a2', 'console_scripts', 'cwltoil')()
File "/usr/local/lib/python2.7/dist-packages/toil/cwl/cwltoil.py", line 580, in main
adjustFiles(builder.job, functools.partial(writeFile, toil.importFile, {}))
File "/usr/local/lib/python2.7/dist-packages/cwltool/process.py", line 128, in adjustFiles
adjustFiles(rec[d], op)
File "/usr/local/lib/python2.7/dist-packages/cwltool/process.py", line 131, in adjustFiles
adjustFiles(d, op)
File "/usr/local/lib/python2.7/dist-packages/cwltool/process.py", line 131, in adjustFiles
adjustFiles(d, op)
File "/usr/local/lib/python2.7/dist-packages/cwltool/process.py", line 126, in adjustFiles
rec["path"] = op(rec["path"])
File "/usr/local/lib/python2.7/dist-packages/toil/cwl/cwltoil.py", line 162, in writeFile
index[x] = (writeFunc(rp), os.path.basename(x))
File "/usr/local/lib/python2.7/dist-packages/toil/common.py", line 570, in importFile
return self.jobStore.importFile(srcUrl)
File "/usr/local/lib/python2.7/dist-packages/toil/jobStores/abstractJobStore.py", line 260, in importFile
return self._importFile(findJobStoreForUrl(url), url)
File "/usr/local/lib/python2.7/dist-packages/toil/jobStores/aws/jobStore.py", line 279, in _importFile
info.copyFrom(srcKey)
File "/usr/local/lib/python2.7/dist-packages/toil/jobStores/aws/jobStore.py", line 826, in copyFrom
headers=self._s3EncryptionHeaders()).version_id
File "/usr/local/lib/python2.7/dist-packages/toil/jobStores/aws/jobStore.py", line 865, in _copyKey
headers=headers)
File "/usr/local/lib/python2.7/dist-packages/boto/s3/bucket.py", line 888, in copy_key
response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 400 Bad Request
<Error><Code>InvalidRequest</Code><Message>The specified copy source is larger than the maximum allowable size for a copy source: 5368709120</Message><RequestId>CCB50A66B881B563</RequestId><HostId>1dAVKee/hXEaLCvisKyxUHlWtLbZwqcedEXOsKVSzAoE5ISrsuykzg9teW9vzidQaIqImJxbNgI=</HostId></Error>

# Fixed code
def _extractKeyInfoFromUrl(url, existing=None):
    """
    Extracts bucket and key from URL. The existing parameter determines if a
    particular state of existence should be enforced. Note also that if existing
    is not True and the key does not exist.

    :param existing: determines what the state
    :return: (bucket, key)
    """
    s3 = boto.connect_s3()
    bucket = s3.get_bucket(url.netloc)
    key = bucket.get_key(url.path[1:])

    if existing is True:
        if key is None:
            raise RuntimeError("Key does not exist.")
    elif existing is False:
        if key is not None:
            raise RuntimeError("Key exists.")
    elif existing is None:
        pass
    else:
        assert False

    if key is None:
        key = bucket.new_key(url.path[1:])

    return bucket, key