From ec05beb87d02cae34d9d4a0a84d7f2c1c661be42 Mon Sep 17 00:00:00 2001 From: Nuno Subtil Date: Mon, 5 Dec 2016 23:06:59 +0000 Subject: [PATCH] Fix up temporary file usage for Windows On Windows you can't overwrite a file that you're holding an open file handle for. Create a temporary file with delete=false and reuse the filename instead. (This is less than ideal, but at least makes git-p4 work on Windows.) --- git-p4 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/git-p4 b/git-p4 index 7525d2d..c3f842c 100755 --- a/git-p4 +++ b/git-p4 @@ -780,10 +780,11 @@ class P4FileReader: if header['type'].startswith('utf16'): # Don't even try to convert utf16. Ask p4 to write the file directly. - tmpFile = tempfile.NamedTemporaryFile() - P4Helper().p4_system("print -o \"%s\" \"%s\"" % (tmpFile.name, escapeStringP4(header['depotFile']))) - text = open(tmpFile.name).read() - tmpFile.close() + with tempfile.NamedTemporaryFile(delete=False) as tmpFile: + tmpFileName = tmpFile.name + P4Helper().p4_system("print -o \"%s\" \"%s\"" % (tmpFileName, escapeStringP4(header['depotFile']))) + print "done" + text = open(tmpFileName).read() else: text = textBuffer.getvalue() textBuffer.close()