google-code-export / google-api-python-client

Automatically exported from code.google.com/p/google-api-python-client
Other
1 stars 0 forks source link

MediaBaseIoDownload does not detect when underlying media changes #258

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
## Steps ##

MediaBaseIoDownload downloads by issuing multiple requests with different range 
headers, however it does not ensure that each request is fetching the same data.

For example:

first = 'AA'
requests.put(URL, data=first)
part1 = requests.get(URL, headers={'range': 'bytes 0-0'})
second = 'BB'
requests.put(URL, data=second)
part2 = requests.get(URL, headers={'range': 'bytes 1-1'})

It is obvious that:

assert part1 + part2 not in [first, second]

That is equivalent to the following code:
 URL = os.path.join(ROOT, BUCKET, OBJECT)
 requests.put(URL, data=first)
 mutant = io.BytesIO()
 downloader = http.MediaIoBaseDownload(mutant, storage.objects().get_media(bucket=BUCKET, object=OBJECT, chunksize=1))
 downloader.next_chunk()
 requests.put(URL, data=second)
 downloader.next_chunk()
 mutant.seek(0)
 assert mutant.read() not in [first, second] 

## Expected ##

I would expect to download AA, BB or get an exception. Either downloading the 
object in a single request or else tracking the etag will do this.

## Version

linux, pip install google-api-python-client

Original issue reported on code.google.com by fe...@google.com on 8 Apr 2013 at 5:42