From 5d0fc9a787fe47f7cd0222a97b34558a9dc4c9d1 Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Thu, 1 Dec 2011 00:42:56 +0000 Subject: [PATCH] Handle exceptions thrown when shelling out svn commit So temporary files aren't left around. R=dpranke@chromium.org BUG= TEST= Review URL: http://codereview.chromium.org/8758004 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@112358 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/gcl.py b/gcl.py index 2a52df5fb..f6de1f7e9 100755 --- a/gcl.py +++ b/gcl.py @@ -1000,19 +1000,25 @@ def CMDcommit(change_info, args): handle, commit_filename = tempfile.mkstemp(text=True) os.write(handle, commit_message) os.close(handle) - - handle, targets_filename = tempfile.mkstemp(text=True) - os.write(handle, "\n".join(change_info.GetFileNames())) - os.close(handle) - - commit_cmd += ['--file=' + commit_filename] - commit_cmd += ['--targets=' + targets_filename] - # Change the current working directory before calling commit. - previous_cwd = os.getcwd() - os.chdir(change_info.GetLocalRoot()) - output = RunShell(commit_cmd, True) - os.remove(commit_filename) - os.remove(targets_filename) + try: + handle, targets_filename = tempfile.mkstemp(text=True) + os.write(handle, "\n".join(change_info.GetFileNames())) + os.close(handle) + try: + commit_cmd += ['--file=' + commit_filename] + commit_cmd += ['--targets=' + targets_filename] + # Change the current working directory before calling commit. + previous_cwd = os.getcwd() + os.chdir(change_info.GetLocalRoot()) + output = '' + try: + output = RunShell(commit_cmd, True) + except subprocess2.CalledProcessError, e: + ErrorExit('Commit failed.\n%s' % e) + finally: + os.remove(commit_filename) + finally: + os.remove(targets_filename) if output.find("Committed revision") != -1: change_info.Delete()