From a83663a08c03c64b0a4235a1461005a21447944a Mon Sep 17 00:00:00 2001 From: "tandrii@chromium.org" Date: Thu, 14 Jan 2016 16:01:00 +0000 Subject: [PATCH] Fix git cl upload --squash (for Gerrit). R=bauerb@chromium.org,andybons@chromium.org BUG= Review URL: https://codereview.chromium.org/1590473002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298270 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/git_cl.py b/git_cl.py index ff83f10edc..c72d391d77 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2029,12 +2029,21 @@ def GerritUpload(options, args, cl, change): 'commit-msg') file_handle, msg_file = tempfile.mkstemp(text=True, prefix='commit_msg') + logging.debug("%s %s", file_handle, msg_file) try: try: - with os.fdopen(file_handle, 'w') as fileobj: + try: + fileobj = os.fdopen(file_handle, 'w') + except OSError: + # if fdopen fails, file_handle remains open. + # See https://docs.python.org/2/library/os.html#os.fdopen. + os.close(file_handle) + raise + with fileobj: + # This will close the file_handle. fileobj.write(change_desc.description) + logging.debug("%s %s finish editing", file_handle, msg_file) finally: - os.close(file_handle) RunCommand([commit_msg_hook, msg_file]) change_desc.set_description(gclient_utils.FileRead(msg_file)) finally: