mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-10 14:43:34 +00:00
Use openFile/closeFile to avoid traps (#776)
* Use openFile/closeFile to avoid traps This code isn't necessary, it will happen as part of close f.flush() os.fsync(f.fileno()) * Put flush/sync back
This commit is contained in:
10
src/gam.py
10
src/gam.py
@ -7611,18 +7611,18 @@ def doDownloadVaultExport():
|
|||||||
filename = os.path.join(targetFolder, s_object.replace(u'/', u'-'))
|
filename = os.path.join(targetFolder, s_object.replace(u'/', u'-'))
|
||||||
print u'saving to %s' % filename
|
print u'saving to %s' % filename
|
||||||
request = s.objects().get_media(bucket=bucket, object=s_object)
|
request = s.objects().get_media(bucket=bucket, object=s_object)
|
||||||
f = open(filename, 'wb')
|
f = openFile(filename, 'wb')
|
||||||
downloader = googleapiclient.http.MediaIoBaseDownload(f, request)
|
downloader = googleapiclient.http.MediaIoBaseDownload(f, request)
|
||||||
done = False
|
done = False
|
||||||
while not done:
|
while not done:
|
||||||
status, done = downloader.next_chunk()
|
status, done = downloader.next_chunk()
|
||||||
sys.stdout.write(u' Downloaded: {0:>7.2%}\r'.format(status.progress()))
|
sys.stdout.write(u' Downloaded: {0:>7.2%}\r'.format(status.progress()))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stdout.write(u'\n Download complete, flushing to disk...\n')
|
sys.stdout.write(u'\n Download complete\n')
|
||||||
f.flush()
|
f.flush()
|
||||||
os.fsync(f.fileno())
|
os.fsync(f.fileno())
|
||||||
f.close()
|
closeFile(f)
|
||||||
f = open(filename, 'rb')
|
f = openFile(filename, 'rb')
|
||||||
if verifyFiles:
|
if verifyFiles:
|
||||||
expected_hash = s_file['md5Hash']
|
expected_hash = s_file['md5Hash']
|
||||||
sys.stdout.write(u' Verifying file hash is %s...' % expected_hash)
|
sys.stdout.write(u' Verifying file hash is %s...' % expected_hash)
|
||||||
@ -7636,7 +7636,7 @@ def doDownloadVaultExport():
|
|||||||
else:
|
else:
|
||||||
print u'ERROR: actual hash was %s. Exiting on corrupt file.' % actual_hash
|
print u'ERROR: actual hash was %s. Exiting on corrupt file.' % actual_hash
|
||||||
sys.exit(6)
|
sys.exit(6)
|
||||||
f.close()
|
closeFile(f)
|
||||||
if extractFiles and re.search(r'\.zip$', filename):
|
if extractFiles and re.search(r'\.zip$', filename):
|
||||||
extract_nested_zip(filename, targetFolder)
|
extract_nested_zip(filename, targetFolder)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user