From b8c6800b37d95dcf3d8d3bb86dda9d3596598d31 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Fri, 3 Aug 2018 12:57:23 -0700 Subject: [PATCH] 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 --- src/gam.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gam.py b/src/gam.py index 33438acf..3e427ed1 100755 --- a/src/gam.py +++ b/src/gam.py @@ -7611,18 +7611,18 @@ def doDownloadVaultExport(): filename = os.path.join(targetFolder, s_object.replace(u'/', u'-')) print u'saving to %s' % filename request = s.objects().get_media(bucket=bucket, object=s_object) - f = open(filename, 'wb') + f = openFile(filename, 'wb') downloader = googleapiclient.http.MediaIoBaseDownload(f, request) done = False while not done: status, done = downloader.next_chunk() sys.stdout.write(u' Downloaded: {0:>7.2%}\r'.format(status.progress())) sys.stdout.flush() - sys.stdout.write(u'\n Download complete, flushing to disk...\n') + sys.stdout.write(u'\n Download complete\n') f.flush() os.fsync(f.fileno()) - f.close() - f = open(filename, 'rb') + closeFile(f) + f = openFile(filename, 'rb') if verifyFiles: expected_hash = s_file['md5Hash'] sys.stdout.write(u' Verifying file hash is %s...' % expected_hash) @@ -7636,7 +7636,7 @@ def doDownloadVaultExport(): else: print u'ERROR: actual hash was %s. Exiting on corrupt file.' % actual_hash sys.exit(6) - f.close() + closeFile(f) if extractFiles and re.search(r'\.zip$', filename): extract_nested_zip(filename, targetFolder)